Configure Tomcat JDBC Connection Pool in server.xml 

Joined:
04/09/2007
Posts:
784

September 18, 2013 19:54:58    Last update: September 18, 2013 19:54:58
You can define a JDBC datasource in $CATALINA_BASE/conf/server.xml under <GlobalNamingResources> like this:
<GlobalNamingResources>
	<Resource name="jdbc/MyDataSource"
	      auth="Container"
	      type="javax.sql.DataSource"
	      username="username"
	      password="password"
	      driverClassName="oracle.jdbc.driver.OracleDriver"
	      url="jdbc:oracle:thin:@oracle.local:1521:mydata"
	      factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
	      removeAbandonedTimeout="60"
              removeAbandoned="true"
	      maxActive=""
	      maxIdle="1"/>
</GlobalNamingResources>


But you will not be able to lookup the datasource in your webapp, unless you define a link in your per-web-application JNDI context (for example, META-INF/context.xml):
<?xml version="1.0"?>
<Context>
    <ResourceLink
	name="jdbc/MyDataSource"
	global="jdbc/MyDataSource"
	type="javax.sql.DataSource"/>
</Context>


By tomcat documentation:

The GlobalNamingResources element defines the global JNDI resources for the Server.

These resources are listed in the server's global JNDI resource context. This context is distinct from the per-web-application JNDI contexts described in the JNDI Resources HOW-TO. The resources defined in this element are not visible in the per-web-application contexts unless you explicitly link them with <ResourceLink> elements.

Share |
| Comment  | Tags