SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)
ResultSet rs = getSalary.executeQuery();
rs.next();
newSalary[0] = rs.getBigDecimal(1);
rs.close();
conn.close();
}
CREATE PROCEDURE Statement
CREATE PROCEDURE samdbcat.persnl.adjustsalary(IN empnum NUMERIC(4),
IN percent FLOAT,
OUT newsalary NUMERIC(8,2))
EXTERNAL NAME 'Payroll.adjustSalary'
EXTERNAL PATH '/usr/mydir/myclasses'
LANGUAGE JAVA
PARAMETER STYLE JAVA
MODIFIES SQL DATA;
CALL Statement to Invoke the SPJ
To invoke the ADJUSTSALARY procedure in MXCI:
CALL samdbcat.persnl.adjustsalary(29, 2.5, ?);
The ADJUSTSALARY procedure updates the salary of employee number 29 by 2.5 percent and
returns this output in MXCI:
NEWSALARY
------------
139400.00
--- SQL operation complete.
The salary of employee number 29 was originally $136,000.00 and became $139,400.00 after
the invocation of ADJUSTSALARY.
EMPLOYEEJOB Stored Procedure
Java Method
public static void employeeJob(int empNum,
java.lang.Integer[] jobCode)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement getJobcode =
conn.prepareStatement("SELECT jobcode " +
"FROM samdbcat.persnl.employee " +
"WHERE empnum = ?");
getJobcode.setInt(1, empNum);
ResultSet rs = getJobcode.executeQuery();
rs.next();
int num = rs.getInt(1);
if (rs.wasNull())
jobCode[0] = null;
else
jobCode[0] = new Integer(num);
rs.close();
conn.close();
}
CREATE PROCEDURE Statement
CREATE PROCEDURE samdbcat.persnl.employeejob(IN empnum INT,
OUT jobcode INT)
EXTERNAL NAME 'Payroll.employeeJob(int, java.lang.Integer[])'
118 Sample SPJs










