As soon as my code gets to my while(rs.next())
loop it produces the ResultSet
is closed exception. What causes this exception and how can I correct for it?
EDIT: I notice in my code that I am nesting while(rs.next())
loop with another (rs2.next())
, both result sets coming from the same DB, is this an issue?
You should explicitly close Statements , ResultSets , and Connections when you no longer need them, unless you declare them in a try -with-resources statement (available in JDK 7 and after). Connections to Derby are resources external to an application, and the garbage collector will not close them automatically.
In the mean time many result sets might opened and left unclosed. If it happens on a single database by multiple applications, the data updation is not perfect and may violate ACID properties rule for data presuming.
The ResultSet object contains a cursor/pointer which points to the current row. Initially this cursor is positioned before first row (default position). The isClosed() method of the ResultSet interface is used to determine whether the current ResultSet object is closed.
Sounds like you executed another statement in the same connection before traversing the result set from the first statement. If you're nesting the processing of two result sets from the same database, you're doing something wrong. The combination of those sets should be done on the database side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With