DBCP Connection Pooling Example

By | August 5, 2018

In previous post MysqlDataSource example we learnt about how to take JDBC connection using  MysqlDataSource connection pool
In this post we will learn about DBCP Connection Pooling using an example

Note:You have to add few dependencies binaries in your project class path those dependencies you can see in the blow project lib folder 

Project structure in eclipse:

Create database.properties file in src folder as shown in the above project structure and make entry of below properties.

SQL Query to create employee_table in MySQL (jdbcpooldb schema) 

Once you execute above db script your database schema(jdbcpooldb) will be created and employee_table will be created with three rows as below. 

Utility class which is responsible to get JDBC connection object using Apache DBCP DataSource connection pool With MYSQL Database.

Client class makes use of DBUtil.getDataSource() method to take connection from Apache DBCP connection pool With MYSQL Database.

After running ClientTest.java program you will look below  output on eclipse console:  

Above eclipse console output shows we are able to read rows from MySQL database that means we are successfully taken database connection using Apache DBCP connection pool

That’s all about  this topic DBCP Connection Pooling Example.

You May Also Like:

Why we need a database connection pooling
MysqlDataSource example
C3P0 JDBC connection pool Example
BoneCP connection pool example
Hikari Connection Pooling Example

If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

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