Monday, January 19, 2009

8.1.7 Retrieve OUT Parameters after Results

Because of limitations imposed by some DBMSs, it is recommended that for maximum portability, all of the results in a ResultSet object generated by the execution of a CallableStatement object should be retrieved before OUT parameters are retrieved. When all values have been retrieved from a result set, the method ResultSet.next will return false.

If a CallableStatement object returns multiple ResultSet objects (which is possible only if it is executed with a call to the method execute), all of the results should be retrieved before OUT parameters are retrieved. In this case, to be sure that all results have been accessed, the Statement methods getResultSet, getUpdateCount, and getMoreResults need to be called until there are no more results. When all results have been exhausted, the method getMoreResults returns false, and the method getUpdateCount returns -1.

After all values have been retrieved from ResultSet objects (using ResultSet.getter methods), and after it has been determined that there are no more update counts, values from OUT parameters can be retrieved using CallableStatement.getter methods. Similar to the ResultSet getter methods, the CallableStatement getter methods have two forms, one that uses the column index to indicate the column from which to retrieve a value, and one that uses the column name to indicate the column. Note that the getter methods using the column name were added in the JDBC 3.0 API, so check that your driver implements this feature before using it.

0 Comments: