This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "diferent behaviour for diferent mySql drivers" Watch "diferent behaviour for diferent mySql drivers" New topic

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

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

Joined: Oct 14, 2005
Posts: 19725

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

Joined: Dec 20, 2006
Posts: 2543

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
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: diferent behaviour for diferent mySql drivers
It's not a secret anymore!