[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-java
Subject:    RE: JDBC ResultSet exception
From:       "Allen Weeks" <allen.weeks () starband ! net>
Date:       2004-04-30 17:19:44
Message-ID: LNEFKGPPPIFADGFPFIAOEEABCNAA.allen.weeks () starband ! net
[Download RAW message or body]

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:morten@magisterludi.com]
> Sent: Friday, April 30, 2004 9:46 AM
> To: bjoern.wuest@gmx.net
> Cc: java@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                             morten@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=allen.weeks@starband.net


-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/java?unsub=mysql-java@progressive-comp.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic