Saturday, April 09, 2011

Database Connection Pooling with Tomcat

I was facing issue with my tomcat setup where it was running out of DB connection and throwing the following error.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

I had to dive a bit into jdbc connection pooling in Tomcat to get that resolved. onjava.com has helpful article, i thought i would share it with you all.

- link - Database connection pooling with Tomcat by Kunal Jaggi

Steps to create a DataBase source with no connection timeouts in tomcat

Step-1 : Create the Resource entry in context.xml

autoReconnect=true“
maxWait=”100″
removeAbandoned=”true”
maxActive=”3000″
maxIdle=”100″
autoReconnect=”true”
removeAbandonedTimeout=”60″
logAbandoned=”true”/>

Step-2 : Create the entry for ” res-ref-name” which points to the Resource name in context.xml in the web.xml under your application in the webapps/your_app_fldr/WEB-INF/web.xml


DB Connection
jdbc/mysql
javax.sql.DataSource
Container

No comments: