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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
