2

In my spring-hibernate application, we are using org.apache.tomcat.jdbc.pool.DataSource for connection pooling. When we start the server, we are able to see the connection to the DB is established and after the mysql service is stopped the server starts throwing error saying that the connection is lost. When the mysql service is started again, should we have to restart the server to reestablish the connections to the DB? Cuz even after providing autoReconnect=true parameter, the application is not able to establish connection to the DB.

1

2 Answers 2

1

Try adding the following parameters :

validationQuery="SELECT 1"
testOnBorrow="true"

How it works: The connection-pool tries running validationQuery before returning the connection. If the validationQuesry fails, dbcp discard the connection, creates a new one and return it.

Here's an example:

<Resource   name="jdbc/cooldatabase"
            description="Strandls.com license database"
            auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/cooldatabase?autoReconnect=true"
            username="cooluser"
            password="coolpassword"
            initialSize="0"
            maxActive="20"
            maxIdle="10"
            minIdle="0"
            maxWait="-1"
            validationQuery="SELECT 1"
            testOnBorrow="true"
            poolPreparedStatements="true"
            removeAbandoned="true"
            removeAbandonedTimeout="60"
            logAbandoned="true"/>

Complete details : http://amitcodes.com/2008/07/26/16/

Sign up to request clarification or add additional context in comments.

Comments

0

I tried using dbcp and c3p0. I found certain problems in dbcp but c3p0 is working fine.

autoReconnect=true

Now my application is able to reconnect to MySQL DB automatically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.