Search code examples
tomcatjdbcconnection-poolingtomcat6

JDBC Connection pool not reopening connections in Tomcat


I have set up Tomcat to use a connection pool yet after the MySQL timeout on connections the connections previously open in the pool are not opened. Here is what my context.xml file looks like:

<Resource name="jdbc/hpsgDB" auth="Container" type="javax.sql.DataSource"
           maxActive="5" maxIdle="3" maxWait="10000"
           username="uname" password="password" driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:3306/hpsgdb?autoReconnect=true"/>

As you can see I have included autoReconnect as true yet it doesn't. I have checked the process on the database after 8 hours which is what the time out is set to.


Solution

  • Try adding a validation query attribute. This should have the effect of automatically closing and re-opening the connection after a timeout like this:

    validationQuery="SELECT 1"