IBM Support

"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 ( to the Data Server Driver for JDBC (db2jcc.jar) the following error now occurs "Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null"

Symptom [jcc][t4][10120] [10898][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 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 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 returns false instead of throwing an SQLException.

For further discussion on this topic, visit this developerWorks forum thread:

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Programming Interface - JDBC","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.7;9.5;9.1","Edition":"Enterprise Server Edition","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018