Creating a connection to the database server is expensive. It is even more expensive if the server is located on another machine. Connection pool contains a number of open database connections which we can configure as minimum and maximum. There are lot of APIs available to create connection pooling also we can depend application server if it supports this feature, generally all the applications servers support connection pools. It creates the connection pool on behalf of you when it starts.
Here is one simple example which creates a connection pool maximum of size 5.
Prerequisites- mysql-connector-java-5.1.5-bin.jar should be there in the project class path.
Test Connection Pool(ConnectionPoolTest.java)
The above connection pool class we set the maximum number of connections as 5, in this test class we will create first 5 connections and release one connection and creates 6th connection ..see below example