GeeCON Prague 2014*
The moose likes JDBC and the fly likes diferent behaviour for diferent mySql drivers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "diferent behaviour for diferent mySql drivers" Watch "diferent behaviour for diferent mySql drivers" New topic
Author

diferent behaviour for diferent mySql drivers

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
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)


java amateur
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Feb 08, 2004
Posts: 1281
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

Joined: Dec 20, 2006
Posts: 2501
    
    8

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;


OCUP UML fundamental and ITIL foundation
youtube channel
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: diferent behaviour for diferent mySql drivers