11 messages in com.mysql.lists.javaRe: JDBC ResultSet exception| From | Sent On | Attachments |
|---|---|---|
| Bjoern Wuest | 29 Apr 2004 23:59 | |
| Rhino | 30 Apr 2004 07:39 | |
| Bjoern Wuest | 30 Apr 2004 08:16 | |
| Jae Joo | 30 Apr 2004 08:28 | |
| Rhino | 30 Apr 2004 08:53 | |
| Bjoern Wuest | 30 Apr 2004 09:26 | |
| Bjoern Wuest | 30 Apr 2004 09:30 | |
| Morten Norby Larsen | 30 Apr 2004 09:45 | |
| Bjoern Wuest | 30 Apr 2004 10:11 | |
| Allen Weeks | 30 Apr 2004 10:19 | |
| Morten Norby Larsen | 03 May 2004 02:33 |
| Subject: | Re: JDBC ResultSet exception![]() |
|---|---|
| From: | Morten Norby Larsen (mor...@magisterludi.com) |
| Date: | 05/03/2004 02:33:04 AM |
| List: | com.mysql.lists.java |
Right, you definitely need to close the statement after use - this is where for instance ODBC gets very fuzzy if you don't, while Connector/(J is more forgiving. Sorry for my sloppy advice.
Morten
Allen Weeks wrote:
If I am not mistaken, for what you are attempting you must also close the statement varible as well. You could them use the same names again for both Statement and ResultSet varibles.
Hope this helps
-----Original Message----- From: Morten Norby Larsen [mailto:mor...@magisterludi.com] Sent: Friday, April 30, 2004 9:46 AM To: bjoe...@gmx.net Cc: ja...@lists.mysql.com Subject: Re: JDBC ResultSet exception
You use the same Statement instance twice. I am not sure that is allowed by the JDBC spec, but I am talking out of the top of my head, so please do not take it for more than it is.
However, it wouldn't hurt closing the statement object and create a new one for your next query. Probably also more portable (ODBC is fuzzy about these issues).
Hope this helps, Morten
Bjoern Wuest wrote:
Dear all
Due to some discussion I decided to reformulate a previous request of o problem I have with MySQL and JDBC.
My problem:
I work on a small application with database support. For
development I use
the MySQL database which is just doing fine. During testing I
experienced a,
in my opinion, strange bug.
I have the following source code:
Connection conn = ... // get JDBC connection object to MySQL
database from
somewhere try { Statement stmt = null; ResultSet rSet = null; try { // Create statement from connection stmt = conn.createStatement(); // Read some data from database (works perfect) rSet = stmt.executeQuery("select v from config where k='time'"); rSet.next(); String ttl = rSet.getString("v"); rSet.close(); rSet = null; // Read some other data from database rSet = stmt.executeQuery("select v from config where k='location'"); while (rSet.next()) { // Do something in here } rSet.close(); } catch (SQLException Ex) { // Notify about exception } finally { // Do some cleanup work if (rSet != null) { try { rSet.close(); } catch (SQLException Ignore) {} rSet = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException Ignore) {} stmt = null; } } } finally { // Close the JDBC connection to the MySQL database if (conn != null) { try { conn.close(); } catch (SQLException
Ignore) {} }
}
<<<<<<<<<<<<<<<<<<
Now the problem I encounter:
The first query ("select v from config where k='time'") is
executed without
any problems. I can read the returned value and save in 'ttl'.
Then, I close
this result set and leave it to the garbage collector. Next, I
want to use
the same variable to take the result set of another query
("select v from
config where k='location'") which is executed as well. But then, when I execute "while (rSet.next())" I get the following exception:
java.sql.SQLException: Operation not allowed after ResultSet closed at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:4579) at com.mysql.jdbc.ResultSet.next(ResultSet.java:2423) at
net.sos.web.services.mapping.CMySQLMappingService$1.run(CMySQLMapp ingService
.java:323) at java.lang.Thread.run(Unknown Source)
<<<<<<<<<<<<<<<<<<
"while (rSet.next())" is on line 323 in an anonymous class
implementation of
java.lang.Runnable, but I think this is not the reason for the
exception.
I use Connection/J in version 3.1.1alpha and MySQL 5.0.0alpha (I have to because of some features unique to MySQL 5). The JDK I use is 1.4.2_02
I hope someone can help me since I have really no clue why this is happening. Temporarily I don't close the result set but this
would result in
a lot of memory consumption in my system.
Thanks Bjoern
-- Morten Norby Larsen mor...@magisterludi.com Magister Ludi s.r.l. Phone: +39 02 26 11 72 80 Via Battaglia 8, I-20127 Milano, Italy Fax: +39 02 28 46 037 http://www.magisterludi.com
-- MySQL Java Mailing List For list archives: http://lists.mysql.com/java To unsubscribe:
http://lists.mysql.com/java?unsub=alle...@starband.net
-- Morten Norby Larsen mor...@magisterludi.com Magister Ludi s.r.l. Phone: +39 02 26 11 72 80 Via Battaglia 8, I-20127 Milano, Italy Fax: +39 02 28 46 037 http://www.magisterludi.com




