EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #62 background imageLoading...
Page #62 background image
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.
5. If the stored procedure returns multiple result sets, retrieve the result sets.
Restriction: IDS data sources do not support multiple result sets.
6. Invoke the CallableStatement.getXXX methods to retrieve values from the OUT
parameters or INOUT parameters.
7. Invoke the CallableStatement.close method to close the CallableStatement
object when you have finished using that object.
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(?,?,?,?,?)"); 1
// Create a CallableStatement object
cstmt.setString (1, "DISPLAY THREAD(*)"); 2
// Set input parameter (DB2 command)
cstmt.registerOutParameter (2, Types.INTEGER); 3
// Register output parameters
cstmt.registerOutParameter (3, Types.INTEGER);
cstmt.registerOutParameter (4, Types.INTEGER);
cstmt.registerOutParameter (5, Types.VARCHAR);
cstmt.executeUpdate(); // Call the stored procedure 4
ifcaret = cstmt.getInt(2); // Get the output parameter values 6
ifcareas = cstmt.getInt(3);
xsbytes = cstmt.getInt(4);
errbuff = cstmt.getString(5);
cstmt.close(); 7
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
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.
Related tasks
46 Application Programming Guide and Reference for Java

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability