How to Use Connection Pooling?

by Dr. Wenjie He

In web applications, the performance of database access is extremly important. Establishing and maintaining a database connection is a costly operation. The Connection Pooling technique provides an efficient way to manage the database resource in an application server.

1. Downloading the example

circle The database script: GuestBookCP\db\guestbookdb.sql
circle Two JSP files: GuestBookCP\jsp\guestBookView.jsp, guestBookLogin.jsp
circle Two JavaBeans: GuestBookCP\src\org\me\jsp\beans\,
circle Two XML configuration files: GuestBookCP\config\web.xml, context.xml,

2. Creating the database

If you have never done this before, read this tutorial A Shortcut to Create MySQL Databases first.

If you did this tutorial How to Use JavaBeans in JSPs? before, you can skip this step.

3. Running the example

If you want to know how to create a Dynamic Web Project, a package, and a servlet in Eclipse for Java EE, and how to run the project, see the tutorial Developing a Web Application in Eclipse for Java EE

4 Database connections

5 Connection pool

6 Drawbacks of the non-connection pooling approach

7 How does a connection pool improve the performance?

8 How to set up a connection pool in a server?

For different servers, the way to set up a connection pool is different. Here we only talk about how to set up a connection pool in Tomcat for the MySQL database.

9 Java Naming and Directory Interface (JNDI)

The Java Naming and Directory Interface (JNDI) is an application programming interface (API) that provides naming and directory functionality to applications written in Java. It is defined to be independent of any specific directory service implementation. Thus a variety of directories can be accessed in a common way.

10 Java EE Naming Services

11 DataSource

A DataSource object is the representation of a data source in the Java programming language. A data source is a facility for storing data.

12 How to use a connection pool in your code?

After the connection pool is set up, a data source is created by the server to associate with a database. To access the database, we use a data source object through the JNDI name.

==========The End==========