aspose file tools*
The moose likes JDBC and the fly likes MySQL Connector/J: autoReconnectForPools Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL Connector/J: autoReconnectForPools" Watch "MySQL Connector/J: autoReconnectForPools" New topic

MySQL Connector/J: autoReconnectForPools

Brian R. Wainwright
Ranch Hand

Joined: Aug 12, 2003
Posts: 92
Does anyone know if the "autoReconnectForPools" parameter for the is what I need to use to resolve stale connections to the database throwing:

because MySQL closes connections after 8 hours of inactivity? My specific implementation, just as an FYI (although I'm not sure if its totally relevant) is I'm using Hibernate as a persistence layer and their DBCPConnectionPool implementation.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
I've used DBCP with Oracle and I ran into a similar problem. The fix was to specify a "validQuery" parameter (something simple and quick) that the underlying connection pool would use to validate the query before handing it back. Since then my app has been running (2 months and counting) w/out any problem.
I have used hibernate a bit in connection with Tomcat and JNDI, and I believe you can define the DataSource to include a "validQuery" parameter. Hopefully it will solve your problem.
Brian R. Wainwright
Ranch Hand

Joined: Aug 12, 2003
Posts: 92
Thanks Wayne. You are indeed correct. For MySQL a valid validQuery would be something like: "select 1" - for anyone listenign in hibernate you can specify this in the connection pool thusly:

It is sorta covered in the JavaRanch Style Guide.
subject: MySQL Connector/J: autoReconnectForPools
Similar Threads
Strange exception when trying to make remote method call...
java.rmi.UnmarshalException: (RMIunder Linux)
Read time out error
Enable Mailing services
Problem faced in using the Java Mail Api