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


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to