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

List:       mysql-java
Subject:    Re: No operations allowed after connection closed
From:       "Loren Siebert" <loren () siebert ! org>
Date:       2003-10-29 14:16:02
[Download RAW message or body]

Thanks Nick. I do only close my connections once...I always follow this sort
of structure:
try {
    PreparedStatement prepStmt = con.prepareStatement(insertStatement);
try {
    prepStmt.setString(1, foo);
    prepStmt.setInt(2, bar);
    prepStmt.executeUpdate();
} finally {
    prepStmt.close();
}
} finally {
    con.close();
}

I have not been able to reproduce that stack trace in testing and I haven't
seen it again in production, despite frequent mysqld restarts. Nothing has
changed in my code or configurations to make it behave any differently, so I
suppose it's just a matter of time before it happens again.

----- Original Message ----- 
From: "Nick Stuart" <nick@newtsplace.com>
To: <java@lists.mysql.com>
Sent: Wednesday, October 29, 2003 6:14 AM
Subject: Re: No operations allowed after connection closed


> I had this problem as well, and the main problem was that I was closing
the
> connection twice. Once in the try{} block and again in the finally{}
block,
> where it should only be closed in the finally. My thought is that this
> shouldn't matter, but it does and it fixed my errors.
> I don't know if this will help you out as it is a different situation
> (restarting the DB) but its something to look for.
>
> -Nick
>
> Quoting Loren Siebert <loren@siebert.org>:
>
> > Hi James,
> > I am using DBCP (see the last line in my stack trace).
> >
> > Perhaps something is wrong with the connection test? If I am calling
close()
> > on the connection in my "finally" clause, the connection isn't getting
> > closed properly, so that when a subsequent thread asks the DriverManager
for
> > a connection, it returns this incorrectly closed connection, thinking
that
> > it's actually open and available. Just guessing here.
> >
> > For what it's worth, the DB I'm connecting to is a mysql3.23 instance on
> > FreeBSD4.8.
> >
> > ----- Original Message -----
> > From: "James Norman" <jnorman@taregon.com>
> > To: "Loren Siebert" <loren@siebert.org>
> > Cc: <java@lists.mysql.com>
> > Sent: Friday, October 17, 2003 2:43 PM
> > Subject: Re: No operations allowed after connection closed
> >
> >
> > > The connections are closed when you restart the database.  You may
want
> > > to use a database pool such as the DBCP from jakarta.apache.org.  This
> > > will test the connection before returning it, creating and returning a
> > > new connection if the old one is not longer valid.
> > >
> > >
> > > On Fri, 2003-10-17 at 15:33, Loren Siebert wrote:
> > > > I am trying to find out why my pool of connections starts throwing
> > > > exceptions like this whenever my mysql4.0.x instance is restarted:
> > > >
> > > > |java.sql.SQLException: No operations allowed after connection
> > > > closed.||Connection was closed due to the following exception:||**
BEGIN
> > > > NESTED EXCEPTION ** ||java.sql.SQLException|MESSAGE: Communication
link
> > > > failure: java.io.IOException, underlying cause: Unexpected end of
input
> > > > stream||** BEGIN NESTED EXCEPTION ** ||java.io.IOException|MESSAGE:
> > > > Unexpected end of input stream||STACKTRACE:||java.io.IOException:
> > Unexpected
> > > > end of input stream|       at
> > > > com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1405)|   at
> > > > com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1775)|   at
> > > > com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)|       at
> > > > com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)|        at
> > > > com.mysql.jdbc.Connection.execSQL(Connection.java:2030)|     at
> > > >
> >
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1750)|
> > > > at
> > > >
> >
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1596)|
> > > > at
> > > >
> >
org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(Delegating
> > > > PreparedStatement.java:207)|
> > > > ...<snip>
> > > >
> > > > I am running Sun's JRE1.4.2_01 on RH9.0, and just upgraded to
> > > > ConnectorJ3.0.9 (with autoreconnect=true) in hopes that this was a
fix
> > for a
> > > > possible ConnectorJ bug that was alluded to here:
> > > > http://www.raibledesigns.com/page/rd/20030826.
> > > >
> > > > Here is how I wrap the JDBC code in my Java app:
> > > > Connection con = DriverManager.getConnection(getDataSourceName());
> > > > try {
> > > > PreparedStatement prepStmt = con.prepareStatement(insertStatement);
> > > > try {
> > > > prepStmt.setString(1, foo);
> > > > prepStmt.setInt(2, bar);
> > > > prepStmt.executeUpdate();
> > > > } finally {
> > > > prepStmt.close();
> > > > }
> > > > } finally {
> > > > con.close();
> > > > }
> > > >
> > > > Is this a ConnectorJ bug, or am I not cleaning things up properly in
the
> > > > event that a Connection is broken?
> > > >
> > > > -Loren
> > > >
> > > >
> > >
> > >
> > >
> >
> >
> >
> > --
> > MySQL Java Mailing List
> > For list archives: http://lists.mysql.com/java
> > To unsubscribe:    http://lists.mysql.com/java?unsub=nick@newtsplace.com
> >
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> -- 
> MySQL Java Mailing List
> For list archives: http://lists.mysql.com/java
> To unsubscribe:    http://lists.mysql.com/java?unsub=loren@siebert.org
>
>
>



-- 
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