Tag Archives: connection pooling

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

<Resource name=”jdbc/mysql”
auth=”Container”
type=”javax.sql.DataSource”
factory=”org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory”
username=”username”
password=”password”
driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://127.0.0.1:3306/database_name?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

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Advertisements

Leave a comment

Filed under Tomcat