Performing Database Connection Pooling

In the JDBC applications we created so far, we performed the following steps:

  1. Load the JDBC Driver.

  2. Obtain a connection from the Database Manager.

  3. Perform database operations using the connection.

  4. Close the connection.

This simple method is rather inefficient: Loading the driver and obtaining a connection is an expensive operation. No, you don't need to pay royalty fees for each connection! It's expensive because of the overhead involved in the process. Also, DBMSes have a limit on the number of active connections that can be made with each database, so if a connection is to be created for each request, the limit will be breached easily.

We will create a mechanism to pool or reuse database connections. In ...

Get Java Server Pages from scratch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.