It is possible for a query to return multiple results. This can happen when executing a stored procedure, or with databases that also allow submission of multiple
SELECT statements in a single query. Here is how you retrieve all result sets.
1. Use the
execute method to execute the SQL statement.
2. Retrieve the first result or update count.
3. Repeatedly call the
getMoreResults method to move on to the next result set.
4. Finish when there are no more result sets or update counts.
getMoreResults methods return
true if the next item in the chain is a result set. The
getUpdateCount method returns
-1 if the next item in the chain is not an update count.
The following loop traverses all results: