Processing SQL stored procedure calls with a CallableStatement object is accomplished with the same methods that are used with a PreparedStatement object.
If an SQL query statement is processed within a stored procedure, the query results can be made available to the program calling the stored procedure. Multiple queries can also be called within the stored procedure and the calling program can process all the ResultSets that are available.
See Example: Create a procedure with multiple ResultSets for more information.
Return results for stored procedures deals with ResultSets and stored procedures and provides an example that works with all Java™ Development Kit (JDK) releases. In the example, the ResultSets are processed in order from the first ResultSet that the stored procedure opened to the last ResultSet opened. One ResultSet is closed before the next is used.
In JDK 1.4 and subsequent versions, there is support for working with ResultSets from stored procedures concurrently.
Returning update counts for stored procedures is a feature discussed in the JDBC specification, but it is not currently supported on the iSeries™ platform. There is no way to return multiple update counts from a stored procedure call. If an update count is needed from a processed SQL statement within a stored procedure, there are two ways of returning the value:
If the results from a stored procedure call are not known, the execute method should be used. Once this method has been processed, the JDBC driver can tell the application what types of results the stored procedure generated through API calls. The execute method returns true if the result is one or more ResultSets. Updating counts do not come from stored procedure calls.
The iSeries platform supports stored procedures that have a return value similar to a function's return value. The return value from a stored procedure is labeled like other parameters marks and is labeled such that it is assigned by the stored procedure call. An example of this is as follows:
? = CALL MYPROC(?, ?, ?)
The return value from a stored procedure call is always an integer type and must be registered like any other output parameter.
See Example: Create a procedure with return values for more information.