Requirements of getMoreResults()/getMoreResults(int)
lance.andersen at oracle.com
Mon Nov 23 22:50:58 UTC 2015
This is covered in 13.3.3 of the JDBC 3.0 spec and 18.104.22.168, 13.3.3 of the current JDBC spec.
The JDBC 4 made an attempt to clarify but I would have to go back and try and find the discussions and see if any additional clarification might be needed (this is the first request in 11 years :-) )
The original javadoc for getMoreResults was:
* getMoreResults moves to a Statement's next result. It returns true if
* this result is a ResultSet. getMoreResults also implicitly
* closes any current ResultSet obtained with getResultSet.
* There are no more results when (!getMoreResults() &&
* (getUpdateCount() == -1)
* @return true if the next result is a ResultSet; false if it is
* an update count or there are no more results
* @see #execute
boolean getMoreResults() throws SQLException;
On Nov 22, 2015, at 5:26 AM, Mark Rotteveel <mark at lawinegevaar.nl> wrote:
> I just ran into a question on stackoverflow, http://stackoverflow.com/q/33853354/466862 about the requirements for getMoreResults() vs getMoreResults(int).
> The description of getMoreResults() says:
> "and implicitly closes any current ResultSet object(s) obtained with the method getResultSet."
> As it uses **any** and object**(s)**, this sounds to me like its behavior should be the equivalent of getMoreResults(Statement.CLOSE_ALL_RESULTS), however getMoreResults(int) says:
> "SQLFeatureNotSupportedException - if DatabaseMetaData.supportsMultipleOpenResults returns false and either Statement.KEEP_CURRENT_RESULT or Statement.CLOSE_ALL_RESULTS are supplied as the argument."
> This was added in JDBC 4, JDBC 3 had no such requirement.
> So, what is the required behavior for getMoreResults()? Is it always getMoreResults(Statement.CLOSE_CURRENT_RESULT), or is it getMoreResults(Statement.CLOSE_CURRENT_RESULT) in a driver that does not support multiple results, and getMoreResults(Statement.CLOSE_ALL_RESULTS) in a driver that does support multiple open results?
> If the second, then I think for a driver that does not support multiple open results this distinction is unnecessary, because then closing the current result is the same as closing all results (as there is only one open result); and then the requirement to throw SQLFeatureNotSupportedException for Statement.CLOSE_ALL_RESULTS is also unnecessary.
> On a related note, the DatabaseMetData.supportsMultipleOpenResults says:
> "Retrieves whether it is possible to have multiple ResultSet objects returned from a CallableStatement object simultaneously."
> I think CallableStatement should be changed to Statement as you can call stored procedures (or other statements) that have multiple results also with Statement or PreparedStatement.
> Mark Rotteveel
> Mark Rotteveel
Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com
More information about the jdbc-spec-discuss