Retrieving an unknown number of result sets from a stored procedure in a JDBC application
Retrieving an unknown number of result sets from a stored procedure is a more complicated procedure than retrieving a known number of result sets.
About this task
To retrieve result sets when you do not know the number of result sets or their contents, you need to retrieve ResultSets, until no more ResultSets are returned. For each ResultSet, use ResultSetMetaData methods to determine its contents.
After you call a stored procedure, follow these basic steps to retrieve the contents of an unknown number of result sets.
Procedure
Example
CallableStatement cstmt;
ResultSet rs;
…
boolean resultsAvailable = cstmt.execute(); // Call the stored procedure
while (resultsAvailable) { // Test for result sets 1
ResultSet rs = cstmt.getResultSet(); // Get a result set 2a
… // Process the ResultSet
// as you would process
// a ResultSet from a table
resultsAvailable = cstmt.getMoreResults(); // Check for next result set 2c
// (Also closes the
// previous result set)
}