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.
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)
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?
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.
Joined: Feb 08, 2004
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:
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
Joined: Feb 08, 2004
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: http://aspose.com
subject: diferent behaviour for diferent mySql drivers