Tomcat Connection Pooling

With tomcat you can have Jdbc connection pooling.
You can use dbcp however there is a tomcat connection pool implementation.

Before getting started you have to put the database driver jar to the
tomcat/libs directory

For example if you use mysql you need to place the mysql-connector-java.jar inside the tomcat/libs directory

The configuration is pretty much the same however in order to use the tomcat connection pool you need to specify org.apache.tomcat.jdbc.pool.DataSourceFactory at the factory attribute.

On your META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
        <Resource type="javax.sql.DataSource"

And of course you add your choice of connection pool size, max open connections, idle connections etc.

Then you can get the DataSource object and of course a connection. which you have to close after you have your work done in order to release it back to the pool.

Context context = new InitialContext();
DataSource ds = (DataSource) context.lookup( "java:/comp/env/jdbc/baseDB" );	
Connection connection = ds.getConnection();

More on Tomcat JDBC Connection Pool


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.