Member-only story
Why do we need a Database Connection Pool? -every programmer must know
Hello everyone. In this article, we are going to look at Database connections and their life cycle. Then we will look at the Connection Pool, its internals, and why we need to use it. Then we will look at the design patterns on where to place the connection pool. We will then look at the performance issues that can arise from the Database connection pool and conclude the article by looking at the common connection pool frameworks used in Java. Let's get started.

What is a Database Connection?
Any software application needs to store the data in a database and for the application to interact with a database server, we need a Database Connection. The Database connection is nothing but a way for the application software to interact with the database server software and we use the connection to send commands (SQL) to the database and obtain the response from the database in the form of a Result Set.

The database application usually runs in a dedicated server called a database server which is different from the application servers. The database application runs in a specific port in the database server on which the application server can send commands and receive the data. Eg: MySQL database application runs in a default port called 3306 in the database server machine. This is exactly the same way as the backend application running in port 8080.
Whenever a client like a browser or mobile requests data from the backend application, the backend application needs to talk to the database to retrieve the data and respond to the client.
If a backend application wants to connect to the database server application, it needs to make a call over TCP-IP protocol along with the database server IP and Port info and the credentials to connect. The process of the application server connecting to the database server to obtain data is achieved through a mechanism called Database Connection.
To build a Database connection, we need to provide the information like server URL that contains the host, port and the name of…