Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

resultset.next() implicitly closed in MySQL

 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have a problem with resultset implicitly closing after calling
while(resultset.next())

The exact error is:
java.sql.SQLException: Operation not allowed after ResultSet closed at ... mypckg.MyClass.doPost(MyClass.java:123) at ...
Line 123 is while(resultset.next())

The query I was doing is some update statement. It works the first next() then SQLException. When I check the DB the record was updated ... just can't go to the next record and continue updating or if last record return false.

Does anyone know what's the cause to this? I'm using Connector/J 5.1.5 JDBC driver for MySQL.

Also according to the API for java.sql.ResultSet for the next() method
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.

What exactly does this mean? I'm not using input streams or file I/O.

Thanks
 
Scott Selikoff
author
Saloon Keeper
Posts: 4032
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you're reusing the same statement/object when you perform the update. You need to use a separate statement. Also, please post your JDBC code as it would make spotting the error more clear.
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Selikoff:
It's because you're reusing the same statement/object when you perform the update. You need to use a separate statement. Also, please post your JDBC code as it would make spotting the error more clear.


Ah yes Scott, by using different statements per query solves the problem.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic