Skip to content
Advertisement

Operation not allowed after ResultSet closed (mysql, java)

I was stuck with the error , here my line number 42 is while(rs.next()){, please help me with this i am stuck at this for few hrs.

This is my code:

Advertisement

Answer

A Statement object can have only one active ResultSet, so when you execute rs2 = stmt.executeQuery(sql), the first ResultSet (rs) gets closed.

Create two Statement objects, one for rs and another for rs2.

Quoting the javadoc of Statement:

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment’s current ResultSet object if an open one exists.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement