About Connection Pools
See Also
To store, organize, and retrieve data, most applications use relational databases.
Java EE applications access relational databases through the JDBC API.
When accessing a database, the application calls on the following resources:
- JDBC resource. A JDBC resource (data source) provides applications with a means of connecting to a database.
Typically, the administrator creates a JDBC resource for each database accessed by the applications
deployed in a domain. (However, more than one JDBC resource can be created for a database.)
Each JDBC resource has a unique JNDI name.
- JDBC Connection pool. A JDBC connection pool is a group of reusable connections that the
application server maintains for a particular database. When an application closes a connection, the
connection is returned to the pool. Connection pooling reduces the transaction time of connecting to a
database by means of sharing connection objects providing access to a database source, thus avoiding
a new physical connection being created every time a connection is requested.
At runtime, this is what happens when an application connects to a database:
- Lookup JNDI name of JDBC resource. To connect to a database, the application looks up the JNDI name of the JDBC resource (data source) associated with the database.
The JNDI API enables the application to locate the JDBC resource.
- Locate JDBC connection pool. The JDBC resource specifies which connection pool to use.
The pool defines connection attributes such as the database name (URL), user name, and password.
- Retrieve connection from connection pool. The application server retrieves a physical connection from the connection pool that corresponds to the database.
Now that the application is connected to the database, the application can read, modify, and add data to the database.
Applications access the database by making calls to the JDBC API. The JDBC driver translates the application's JDBC calls into the protocol of the database server.
- Close connection. When it is finished accessing the database, the application closes the connection.
The application server returns the connection to the connection pool. Once it is back in the pool, the connection is available for the next application.
- JNDI name. Each resource has a unique JNDI name which specifies its name and location.
Because all resource JNDI names are in the java:comp/env subcontext,
the JNDI name of a JDBC resource is expected in the java:comp/env/jdbc subcontext.
For example, for a database name MyDatabase, specify jdbc/MyDatabase.
- See Also
- Setting up a Connection Pool on the GlassFish Application Server
- Setting up a JDBC Resource on the GlassFish Application Server
- Setting up a Connection Pool on the JBoss Application Server
- Setting up a Connection Pool on the Tomcat Web Server
- Accessing a Connection Pool from a Java Class
Legal Notices