11 messages in com.mysql.lists.javaRe: JDBC ResultSet exception
FromSent OnAttachments
Bjoern Wuest29 Apr 2004 23:59 
Rhino30 Apr 2004 07:39 
Bjoern Wuest30 Apr 2004 08:16 
Jae Joo30 Apr 2004 08:28 
Rhino30 Apr 2004 08:53 
Bjoern Wuest30 Apr 2004 09:26 
Bjoern Wuest30 Apr 2004 09:30 
Morten Norby Larsen30 Apr 2004 09:45 
Bjoern Wuest30 Apr 2004 10:11 
Allen Weeks30 Apr 2004 10:19 
Morten Norby Larsen03 May 2004 02:33 
Subject:Re: JDBC ResultSet exception
From:Rhino (rhi@sympatico.ca)
Date:04/30/2004 07:39:46 AM
List:com.mysql.lists.java

Bjoern,

From your code, it appears that you are trying to lock the *connection*, not the table. I've never seen that done before. I'm pretty new to MySQL but I'm fluent in DB2; in DB2 we normally lock the table with a LOCK TABLE statement if we want to get exclusive use of the table for a while. I assume that MySQL will work the same, although I haven't actually tried it yet.

Maybe if you write your code that way, you'll have better luck.

Dear All

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 = p_GetConnectionFromPool(); try { // Try to lock the database connection to have exclusive access for table locks synchronized (conn) { Statement stmt = null; ResultSet rSet = null; try { // Create statement from connection stmt = conn.createStatement(); // First, read the configured timeout time rSet = stmt.executeQuery("select v from config where k='time'"); rSet.next(); String ttl = rSet.getString("v"); rSet.close(); rSet = null; rSet = stmt.executeQuery("show databases"); 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 { // Place the connection back in the connection pool if (conn != null) { p_Connections.push(conn); } }

<<<<<<<<<<<<<<<<<<

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 ("show databases") 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(CMySQLMappingService

.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