A JDBC connection pool is a group of reusable connections that a web server or application server maintains for a particular database. Applications requesting a connection to a database obtain that connection from the pool. When an application closes a connection, the connection is returned to the pool. Connection pool properties may vary with different database vendors. Some common properties are the URL for the database name, user name, and password.
For detailed information on Tomcat's database connection pooling functionality, see:
The first step in creating a Tomcat database connection pool is to create JDBC resource (also called a data source). A JDBC resource provides applications with a connection to a database. Typically, there is at least one JDBC resource for each database accessed by an application deployed in a domain. It is possible to have more than one JDBC resource for a database. You can create a JDBC resource manually in your server.xml.
To add a JDBC resource manually in the server.xml file:
![]() |
Be aware that you hand-edit the server.xml
file at your own risk; the IDE cannot repair a damaged server.xml
file. You are strongly encouraged to create a backup version of your working
server.xml file before beginning to edit by hand. |
To reference a JDBC resource from a web application:
<resource-ref> <description>Tomcat DBCP</description> <res-ref-name>jdbc/poolDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
Note: Do not double-click the context.xml file. If you do so, the IDE opens the context.xml file in the Context Editor instead of the Source Editor. You cannot add a resource link in the Context Editor. As you cannot open the context.xml file in both the Source Editor and the Context Editor at the same time, the IDE disables Edit in the contextual menu if the context.xml file is opened in the Context Editor.<ResourceLink name="jdbc/poolDB" type="javax.sql.DataSource" global="jdbc/poolDB"/>
Your web application's META-INF/context.xml file should now look similar to the following:
<Context path="/Employees"> <ResourceLink name="jdbc/poolDB" type="javax.sql.DataSource" global="jdbc/poolDB"/> <Logger className="org.apache.catalina.logger.FileLogger" prefix="Employees" suffix=".log" timestamp="true"/> </Context>