Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I recently upgraded the Oracle JDBC driver version from 11.2.0.1 to 12.1.0.1. However, a very strange thing I noticed. In one of my tests I was closing the ResultSet object twice using following code in Java:
if (resSet != null) {
try {
resSet.getStatement().close();
} catch (NullPointerException ne) {
// nothing to do!
// NullPointerException seen at Oracle and Sybase!
This worked without any exception when I used old JDBC driver 11.2.0.1. But when I switch to new JDBC driver 12.1.0.1, it throws an exception:
java.sql.SQLException: Closed Resultset: getStatement
at oracle.jdbc.driver.InsensitiveScrollableResultSet.getStatement(InsensitiveScrollableResultSet.java:272)
Why does this happen? When I checked the JavaDoc of ResultSet it says: Calling the method close on a ResultSet object that is already closed is a no-op.
So now I am confused, calling a close twice is a no-op means it shouldn't throw any exception, right?
I am using JDK7u45 with java.sql.ResultSet.
–
–
As already indicated in the comments, you are not calling ResultSet.close()
, but calling ResultSet.getStatement()
followed by a Statement.close()
instead.
And that call to resSet.getStatement()
is what throws the exception, as is required by the JDBC spec/api doc:
Throws:
SQLException
- if a database access error occurs or this method is called on a closed result set
(emphasis mine)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.