IBM DB2 Manual page 62

Table of Contents

Advertisement

5. If the stored procedure returns multiple result sets, retrieve the result sets.
6. Invoke the CallableStatement.getXXX methods to retrieve values from the OUT
7. Invoke the CallableStatement.close method to close the CallableStatement
Example: The following code illustrates calling a stored procedure that has one
input parameter, four output parameters, and no returned ResultSets. The
numbers to the right of selected statements correspond to the previously-described
steps.
int ifcaret;
int ifcareas;
int xsbytes;
String errbuff;
Connection con;
CallableStatement cstmt;
ResultSet rs;
...
cstmt = con.prepareCall("CALL DSN8.DSN8ED2(?,?,?,?,?)");
cstmt.setString (1, "DISPLAY THREAD(*)");
cstmt.registerOutParameter (2, Types.INTEGER);
cstmt.registerOutParameter (3, Types.INTEGER);
cstmt.registerOutParameter (4, Types.INTEGER);
cstmt.registerOutParameter (5, Types.VARCHAR);
cstmt.executeUpdate();
ifcaret = cstmt.getInt(2);
ifcareas = cstmt.getInt(3);
xsbytes = cstmt.getInt(4);
errbuff = cstmt.getString(5);
cstmt.close();
Retrieving multiple result sets from a stored procedure in a
JDBC application
If you call a stored procedure that returns result sets, you need to include code to
retrieve the result sets.
The steps that you take depend on whether you know how many result sets are
returned, and whether you know the contents of those result sets.
46
Application Programming Guide and Reference for Java
CallableStatement.execute
Invoke this method if the stored procedure returns multiple result sets, or
an unknown number of result sets.
Restriction: IBM Informix Dynamic Server (IDS) data sources do not
support multiple result sets.
Restriction: IDS data sources do not support multiple result sets.
parameters or INOUT parameters.
object when you have finished using that object.
Related tasks
"Learning about a ResultSet using ResultSetMetaData methods" on page 35
"Retrieving multiple result sets from a stored procedure in a JDBC application"
Related reference
"Driver support for JDBC APIs" on page 252
"JDBC differences between the current IBM Data Server Driver for JDBC and
SQLJ and earlier DB2 JDBC drivers" on page 370
Related tasks
// Create a CallableStatement object
// Set input parameter (DB2 command)
// Register output parameters
// Call the stored procedure
// Get the output parameter values
1
2
3
4
6
7

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents