DBCP Connection Pool Spring

DBCP Connection Pool Spring

There are many API’s available which you can use for connection pooling. Many people prefer C3P0 for connection pooling but if you are using Spring with Hibernate C3PO does not works at all if you are using Spring for data source and hibernate get connection from Spring and make call to the database. In that case Apache DBCP is best option. Here I will show how to configure DBCP connection pooling with Spring application. To understand better I will demo Spring web application.

Tools needed:

  • Eclipse
  • MySQL
  • JDK 1.8
  • Maven 3.2
  • Create sample table in MySQL database and insert some dummy data:

  • Insert data some dummy data:

  • Download and import maven project as you will see below:

DBCP Connection Pool Spring

DBCP Connection pooling configuration:

  • dispatcher-servlet.xml:

  • database.properties: Don’t forget to change below properties with yours:

  • SpringMVCController.java:

  • IPersonDAO.java:

  • PersonDAOImpl.java:

  • Remaining files download project and include it. To run this project you could any servers. As I will be running this in tomcat with MYSQL you will see below:

DBCP Connection Pool Spring

DBCP Connection Pool Spring

  • For more infomation please visit Apache DBCP documentation here

download Download Project: ConnectionPoolingDBCPSpring

2 thoughts on “DBCP Connection Pool Spring

Leave a Reply

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