Connection Pool with Tomcat6 and Mysql

Author - Webner

Inside $tomcat_home/conf/context.xml add this inside <Context>

<Resource name=”jdbc/datasourcename” auth=”Container” type=”javax.sql.DataSource” maxActive=”100″ maxIdle=”30″ maxWait=”1000″ username=”dbuser” password=”dbpwd” driverClassName=”com.mysql.jdbc.Driver” url=”jdbc:mysql://localhost:3306/exodus”/>

Now restart tomcat

Inside you web.xml add this before </web-app>:

<description>My DB Connection</description>

Java code to connect:

Context initCtx = new InitialContext();

DataSource ds = (DataSource) initCtx.lookup(“java:comp/env/jdbc/datasourcename”);

Connection connection = ds.getConnection();


Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published.