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.
-
1check this stackoverflow.com/questions/4726512/…NPKR– NPKR2012-08-07 12:42:13 +00:00Commented Aug 7, 2012 at 12:42
Add a comment
|
2 Answers
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/