aspose file tools*
The moose likes JDBC and the fly likes SQLException: Operation not allowed after ResultSet closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException: Operation not allowed after ResultSet closed" Watch "SQLException: Operation not allowed after ResultSet closed" New topic
Author

SQLException: Operation not allowed after ResultSet closed

H Bhoon
Greenhorn

Joined: May 18, 2009
Posts: 7
Hi all,
Please help me with this problem. I use plain JDBC statements/resultsets to do queries on my db. I retrieve history records for a mobile device record like this:



When I later get the history resultset from my historyMap and try to do a historyResultSet.next() I get a "java.sql.SQLException: Operation not allowed after ResultSet closed" exception. Why is this? According to my understanding I specifically create a new resultset object in my loop every time the loop executes precisely so that I DON'T get this error (thus that I don't re-use a resultset object).

Thanks all!

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

a ResultSet is a Database resource, and you should never share or retain it like you have. With database reads you should open the connection, read the data, then return all of the resources (ie close them)
What is possibly happening is that the DB detects that the ResultSet is still open and overdue and cuts it ioff, or the Connection is closed, which causes the ResultSet to be closed. You can't and shouldn't keep them open for extended periods.
Max Maxx
Greenhorn

Joined: Nov 12, 2009
Posts: 1
For JDBC datasource that was set in websphere 6.1 server i solved similar issue from admin console in the following way:

Resources -> JDBC Provider -> select your Provider -> Data Sources -> Custom Properties.
Finally set the key "resultSetHoldability" to the value "1". The possible values are: 1 (HOLD_CURSORS_OVER_COMMIT), 2 (CLOSE_CURSORS_AT_COMMIT).
H Bhoon
Greenhorn

Joined: May 18, 2009
Posts: 7
Hey guys,
Thanks for your replies! I finally used a work around (following from the suggestions of David O'Meara). I created a POJO (HistoryContainer) to hold all data returned from the resultset. After I get my resultset back from running the query, I copy all the data I need from the resultset into my POJO and then I continue working with my POJO instead of with the resultset. This POJO contains an ArrayList to cater for multiple records in my resultset.



Thanks all for replying.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

That's more like it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQLException: Operation not allowed after ResultSet closed