C3P0 JDBC connection pool Example

By | August 5, 2018

In previous couple of posts  MysqlDataSource example and DBCP Connection Pooling Example we learnt about how to take JDBC connection using  MysqlDataSource and Apache DBCP connection pools
In this post we will learn how to take JDBC connection from C3P0 Connection pool.

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 C3P0 DataSource connection pool With MYSQL Database.

This Client  class makes use of DBUtil.getDataSource() method to take connection from  C3P0 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 C3P0 connection pool

That’s all about  this topic C3P0 JDBC connection pool Example.

You May Also Like:

Why we need a database connection pooling
MysqlDataSource example
DBCP Connection Pooling 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 *