"Invalid operation: result set is closed" error with Data Server Driver for JDBC
After upgrading the JDBC driver from the Legacy JDBC Type 2 driver (db2java.zip) to the Data Server Driver for JDBC (db2jcc.jar) the following error now occurs "Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null"
com.ibm.db2.jcc.am.SqlException: [jcc][t4] [4.11.77] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null
The IBM Data Server Driver for JDBC and SQLJ automatically closes the cursor when all rows have been retrieved from a ResultSet. When ResultSet.next is executed after the cursor is closed the SQLException is thrown. This behavior differs from the DB2 JDBC Type 2 drive where the cursor is not automatically closed upon retrieving all rows from a ResultSet.
Resolving the problem
Ensure the connection has not been closed prematurely. Modify the application code to avoid calling ResultSet.next after all rows have been retrieved. Alternatively, it is possible to workaround the issue by enabling the allowNextOnExhaustedResultSet datasource property. With the allowNextOnExhaustedResultSet property set to DB2BaseDataSource.YES (1), and a forward-only cursor is positioned after the last row of a result set, a call to ResultSet.next returns false instead of throwing an SQLException.
For further discussion on this topic, visit this developerWorks forum thread:
More support for:
DB2 for Linux, UNIX and Windows
Programming Interface - JDBC
Software version: 9.1, 9.5, 9.7
Operating system(s): AIX, Linux, Solaris, Windows
Software edition: Enterprise Server Edition
Reference #: 1461670
Modified date: 31 May 2014
Translate this page: