Connection Pooling in JDBC using Apache Commons DBCP

In this Example We will implement the connection pooling in JDBC using Apache Commons DBCP. Now what is Connection Pool? Connection Pool is a cache of database connections so that connection can be reused when future requests to the database are required. Opening a database connection for each user is a wastage of resource and costly. In connection pooling when a connection is created, it is placed in the connection pool and is used again so there is no need to create a new connection. In connection pooling if all connection is used then a new connection is created and added to the pool

Connection Pooling in JDBC using Apache Commons DBCP Example:-

Project structure:-Connection Pooling in JDBC using Apache Commons DBCP

Following jar’s must be in classpath

com.mysql.jdbc_5.1.5.jar
commons-dbcp2-2.1.1.jar
commons-pool2-2.4.2.jar
commons-logging-1.2.jar

output:-

There are many other’s API for connection pooling like C3P0, Proxool, BoneCP.

Leave a Reply

Your email address will not be published. Required fields are marked *

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