ResultSet resultSet; // class variable
...
...
Statement st = null;
try {
st = conn.createStatement();
resultSet = st.getGeneratedKeys();
} catch (Exception e) {
throw e;
} finally {
try {
if (st != null) st.close();
} catch (SQLException e) {
throw e;
}
}
java.sql.SQLException: Operation not allowed after ResultSet closed
My initial guess was I might have executed resultSet.close() somewhere. But it was not the case.
Problem
The actual problem is, ResultSet instance also saves underlying Statement. So, when the underlying Statment is closed (as done in the FINALLY block above), ResultSet is also closed. This causes the problem.
JavaDoc has clearly mentioned this.
When a Statement object is closed, its current ResultSet object, if one exists, is also closed.
When a Statement object is closed, its current ResultSet object, if one exists, is also closed.
No comments:
Post a Comment