This is an example of how to use the CallableStatement interface.
Example: CallableStatement interface
// Connect to iSeries server. Connection c = DriverManager.getConnection("jdbc:db2://mySystem"); // Create the CallableStatement object. // It precompiles the specified call to a stored procedure. // The question marks indicate where input parameters must be set and // where output parameters can be retrieved. // The first two parameters are input parameters, and the third parameter is an output parameter. CallableStatement cs = c.prepareCall("CALL MYLIBRARY.ADD (?, ?, ?)"); // Set input parameters. cs.setInt (1, 123); cs.setInt (2, 234); // Register the type of the output parameter. cs.registerOutParameter (3, Types.INTEGER); // Run the stored procedure. cs.execute (); // Get the value of the output parameter. int sum = cs.getInt (3); // Close the CallableStatement and the Connection. cs.close(); c.close();
For more information, see CallableStatements.