You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Neil Aggarwal <ne...@JAMMConsulting.com> on 2003/10/20 16:30:20 UTC

PoolableConnectionFactory does not notice when a connection closes

Hello:

I used the following code to initialize a DBCP pool to my MySQL
database:
      String connectURI =
"jdbc:"+dbType+"://"+dbHostName+":"+port+"/"+dbName;
      ObjectPool connectionPool = new GenericObjectPool(null);
      Class.forName(driverClassName);
      ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(connectURI,dbUser,dbPass);
      PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory,connectionPool,null,"select
* from JDO_TABLE limit 1",false,true);
      PoolingDataSource dataSource = new
PoolingDataSource(connectionPool);
      pmf = new com.triactive.jdo.PersistenceManagerFactoryImpl();
      ((PersistenceManagerFactoryImpl)pmf).setAutoCreateTables(true);
      pmf.setConnectionDriverName(driverClassName);
      pmf.setConnectionFactory(dataSource);

My app works fine when I initially run it, but if I leave it alone for a
day,
I get this error:

java.sql.SQLException: No operations allowed after connection closed
  at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
  at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:559)
  at
org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingCon
nection.java:237)
  at
com.triactive.jdo.store.DatabaseAdapter.getConnection(DatabaseAdapter.ja
va:727)

Does anyone have any way to fix this?

Thanks,
	Neil.

--
Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
FREE! Valuable info on how your business can reduce operating costs by 
17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: PoolableConnectionFactory does not notice when a connection closes

Posted by Dirk Verbeeck <di...@pandora.be>.
Very strange, even more because also does a setAutoCommit.

Does this happen with v1.1 of pool/dbcp ?

-- Dirk

Neil Aggarwal wrote:

> Dirk:
> 
> If you look at my call to PoolableConnectionFactory:
>   PoolableConnectionFactory(connectionFactory,connectionPool,
> 	null,"select * from JDO_TABLE limit 1",false,true);
> 
> I have a validation query and the testOnBorrow is true by
> default.
> 
> Why would this not work?
> 
> I will try adding the MySQL autoReconnect parameter.
> 
> Thanks,
> 	Neil
> 
> 
> --
> Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
> FREE! Valuable info on how your business can reduce operating costs by 
> 17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com
> 
> 
>>-----Original Message-----
>>From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be] 
>>Sent: Monday, October 20, 2003 12:38 PM
>>To: Jakarta Commons Users List
>>Subject: Re: PoolableConnectionFactory does not notice when a 
>>connection closes
>>
>>
>>This is a common problem, and DBCP has multiple solutions.
>>See http://jakarta.apache.org/commons/dbcp/configuration.html 
>>for details.
>>Solutions:
>>1) test the connection
>>    (testOnBorrow & validationQuery)
>>2) let DBCP close the idle connection before the database does it
>>    (timeBetweenEvictionRunsMillis & minEvictableIdleTimeMillis)
>>3) test in background thread
>>    (timeBetweenEvictionRunsMillis & testWhileIdle & validationQuery)
>>
>>There is also a MySQL solution, add autoReconnect=true to the 
>>database url:
>>jdbc:mysql://localhost:3306/YourDatabaseName?autoReconnect=true
>>
>>Cheers
>>Dirk
>>
>>Neil Aggarwal wrote:
>>
>>>Hello:
>>>
>>>I used the following code to initialize a DBCP pool to my MySQL
>>>database:
>>>      String connectURI =
>>>"jdbc:"+dbType+"://"+dbHostName+":"+port+"/"+dbName;
>>>      ObjectPool connectionPool = new GenericObjectPool(null);
>>>      Class.forName(driverClassName);
>>>      ConnectionFactory connectionFactory = new
>>>DriverManagerConnectionFactory(connectURI,dbUser,dbPass);
>>>      PoolableConnectionFactory poolableConnectionFactory = new
>>>
>>
>>PoolableConnectionFactory(connectionFactory,connectionPool,nul
>>l,"select
>>
>>>* from JDO_TABLE limit 1",false,true);
>>>      PoolingDataSource dataSource = new
>>>PoolingDataSource(connectionPool);
>>>      pmf = new com.triactive.jdo.PersistenceManagerFactoryImpl();
>>>      
>>
>>((PersistenceManagerFactoryImpl)pmf).setAutoCreateTables(true);
>>
>>>      pmf.setConnectionDriverName(driverClassName);
>>>      pmf.setConnectionFactory(dataSource);
>>>
>>>My app works fine when I initially run it, but if I leave 
>>
>>it alone for a
>>
>>>day,
>>>I get this error:
>>>
>>>java.sql.SQLException: No operations allowed after connection closed
>>>  at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
>>>  at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:559)
>>>  at
>>>
>>
>>org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(Del
>>egatingCon
>>
>>>nection.java:237)
>>>  at
>>>
>>
>>com.triactive.jdo.store.DatabaseAdapter.getConnection(Database
>>Adapter.ja
>>
>>>va:727)
>>>
>>>Does anyone have any way to fix this?
>>>
>>>Thanks,
>>>	Neil.
>>>
>>>--
>>>Neil Aggarwal, JAMM Consulting, (972)612-6056, 
> 
> www.JAMMConsulting.com
> 
>>FREE! Valuable info on how your business can reduce operating costs by
> 
> 
>>17% or more in 6 months or less! =>
> 
> http://newsletter.JAMMConsulting.com
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: PoolableConnectionFactory does not notice when a connection closes

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
Dirk:

If you look at my call to PoolableConnectionFactory:
  PoolableConnectionFactory(connectionFactory,connectionPool,
	null,"select * from JDO_TABLE limit 1",false,true);

I have a validation query and the testOnBorrow is true by
default.

Why would this not work?

I will try adding the MySQL autoReconnect parameter.

Thanks,
	Neil


--
Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
FREE! Valuable info on how your business can reduce operating costs by 
17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com

> -----Original Message-----
> From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be] 
> Sent: Monday, October 20, 2003 12:38 PM
> To: Jakarta Commons Users List
> Subject: Re: PoolableConnectionFactory does not notice when a 
> connection closes
> 
> 
> This is a common problem, and DBCP has multiple solutions.
> See http://jakarta.apache.org/commons/dbcp/configuration.html 
> for details.
> Solutions:
> 1) test the connection
>     (testOnBorrow & validationQuery)
> 2) let DBCP close the idle connection before the database does it
>     (timeBetweenEvictionRunsMillis & minEvictableIdleTimeMillis)
> 3) test in background thread
>     (timeBetweenEvictionRunsMillis & testWhileIdle & validationQuery)
> 
> There is also a MySQL solution, add autoReconnect=true to the 
> database url:
> jdbc:mysql://localhost:3306/YourDatabaseName?autoReconnect=true
> 
> Cheers
> Dirk
> 
> Neil Aggarwal wrote:
> > Hello:
> > 
> > I used the following code to initialize a DBCP pool to my MySQL
> > database:
> >       String connectURI =
> > "jdbc:"+dbType+"://"+dbHostName+":"+port+"/"+dbName;
> >       ObjectPool connectionPool = new GenericObjectPool(null);
> >       Class.forName(driverClassName);
> >       ConnectionFactory connectionFactory = new
> > DriverManagerConnectionFactory(connectURI,dbUser,dbPass);
> >       PoolableConnectionFactory poolableConnectionFactory = new
> > 
> PoolableConnectionFactory(connectionFactory,connectionPool,nul
> l,"select
> > * from JDO_TABLE limit 1",false,true);
> >       PoolingDataSource dataSource = new
> > PoolingDataSource(connectionPool);
> >       pmf = new com.triactive.jdo.PersistenceManagerFactoryImpl();
> >       
> ((PersistenceManagerFactoryImpl)pmf).setAutoCreateTables(true);
> >       pmf.setConnectionDriverName(driverClassName);
> >       pmf.setConnectionFactory(dataSource);
> > 
> > My app works fine when I initially run it, but if I leave 
> it alone for a
> > day,
> > I get this error:
> > 
> > java.sql.SQLException: No operations allowed after connection closed
> >   at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
> >   at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:559)
> >   at
> > 
> org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(Del
> egatingCon
> > nection.java:237)
> >   at
> > 
> com.triactive.jdo.store.DatabaseAdapter.getConnection(Database
> Adapter.ja
> > va:727)
> > 
> > Does anyone have any way to fix this?
> > 
> > Thanks,
> > 	Neil.
> > 
> > --
> > Neil Aggarwal, JAMM Consulting, (972)612-6056, 
www.JAMMConsulting.com
> FREE! Valuable info on how your business can reduce operating costs by

> 17% or more in 6 months or less! =>
http://newsletter.JAMMConsulting.com
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: PoolableConnectionFactory does not notice when a connection closes

Posted by Dirk Verbeeck <di...@pandora.be>.
This is a common problem, and DBCP has multiple solutions.
See http://jakarta.apache.org/commons/dbcp/configuration.html for details.
Solutions:
1) test the connection
    (testOnBorrow & validationQuery)
2) let DBCP close the idle connection before the database does it
    (timeBetweenEvictionRunsMillis & minEvictableIdleTimeMillis)
3) test in background thread
    (timeBetweenEvictionRunsMillis & testWhileIdle & validationQuery)

There is also a MySQL solution, add autoReconnect=true to the database url:
jdbc:mysql://localhost:3306/YourDatabaseName?autoReconnect=true

Cheers
Dirk

Neil Aggarwal wrote:
> Hello:
> 
> I used the following code to initialize a DBCP pool to my MySQL
> database:
>       String connectURI =
> "jdbc:"+dbType+"://"+dbHostName+":"+port+"/"+dbName;
>       ObjectPool connectionPool = new GenericObjectPool(null);
>       Class.forName(driverClassName);
>       ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory(connectURI,dbUser,dbPass);
>       PoolableConnectionFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory,connectionPool,null,"select
> * from JDO_TABLE limit 1",false,true);
>       PoolingDataSource dataSource = new
> PoolingDataSource(connectionPool);
>       pmf = new com.triactive.jdo.PersistenceManagerFactoryImpl();
>       ((PersistenceManagerFactoryImpl)pmf).setAutoCreateTables(true);
>       pmf.setConnectionDriverName(driverClassName);
>       pmf.setConnectionFactory(dataSource);
> 
> My app works fine when I initially run it, but if I leave it alone for a
> day,
> I get this error:
> 
> java.sql.SQLException: No operations allowed after connection closed
>   at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
>   at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:559)
>   at
> org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingCon
> nection.java:237)
>   at
> com.triactive.jdo.store.DatabaseAdapter.getConnection(DatabaseAdapter.ja
> va:727)
> 
> Does anyone have any way to fix this?
> 
> Thanks,
> 	Neil.
> 
> --
> Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
> FREE! Valuable info on how your business can reduce operating costs by 
> 17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org