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

Operation not allowed after ResultSet closed.

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that I'm migrating from MySQL ver 4 to ver 5. I had to update the connector jar in order to get it to work. However, now I'm running into some unusual behavior. This code worked perfectly fine with ver 4, but breaks with ver 5 and the updated connector.

Basically, this is the pattern the program uses when talking to the database.

1. Open connection
2. Run SQL statement
3. Close connection
4. Do stuff with result set

MySQL ver 5 is complaining about this and saying that you can't do anything with the result set after you've closed the connection. Is there a reason this changed between versions?

Also, is there a recommended method of dealing with the data? The currrent setup passes around the result set and performs operations on it.

And unfortunately, rewriting everything to use Hibernate isn't an option. Perhaps later, but right now I just need to get the existing functionality working with the newer version of MySQL.

TIA.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. From the java.sql.ResultSet documentation:
"(...)A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.(...)"

And from a random getXXX method defined by ResultSet:
"(...)Throws:
SQLException - if the columnIndex is not valid; if a database access error occurs or this method is called on a closed result set (...)"

So, whatever you were doing, was against the specification of JDBC. Maybe the connector was implemented in the wrong way - for example, old MySQL connectors version 2.xx had this problem. The only thing to do to be in synch with the specs is to change the code, I'm affraid
 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured as much. I just wanted a second opinion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic