Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

diferent behaviour for diferent mySql drivers

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wonder if the following has ever happened to you: using mysql driver 3.XX my application works perfectly, but from the moment i change the mysql driver to version 5.XX i get a dreaded java.sql.sqlexception: operation not allowed after resultset closed error message

here's the code i'm using (against a mysql 5 database)
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the Statement is closed, the ResultSet is closed. The Statement is closed when it goes out of scope. The question is not really why does it work in v3 and not in v5. It should be how did it work in v3 at all? Are you asking how to change your code to avoid the error?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, not quite. The Statement object is probably being closed by a finalizer when it's garbage-collected. But Tom's point is still correct: the new version works differently because it fixed a bug which was caused by careless code which didn't close JDBC objects properly. So now that code throws an exception instead of leaving open connections to the database.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jdbc isnt my strongest point, so i dont understand quite well were the problem with my code might be
here's how i close the connection:
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You close the connection before the resultset is returned, because the finally block executes before the executeQuery() method is exited.
(even though your return statement comes before the finally block, the finally is executed before you exit the method and return the set)à
And a resultset with a closed connection is a closed resultset;
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried (closing the connection after that method) in a bit of code and it worked with v5 driver
thanks a lot Jan, for your very helpful, clear answer
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic