First, install the JDBC Driver
The database driver jar file to put (Tomcat_install) \ common \ lib directory

Second, configure the Connection Pool
1. Overall connection pool configuration, Tomcat in any Web application can be configured to use the connection pool.
In Tomcat's server.xml file to add the following node GlobalNamingResources, connection pool settings
<Resource
name = "jdbc / poolName"
auth = "Container"
type = "javax.sql.DataSource"
maxActive = "100"
maxIdle = "30"
maxWait = "10000"
username = "sa"
password = "password"
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
url = "jdbc: jtds: sqlserver: / / localhost: 1433; DatabaseName = pubs" />
Note: name for the connection pool of global JNDI name

Set at the overall situation inside context.xml visit Name:
<ResourceLink
global = "jdbc / poolName"
name = "jdbc / poolName"
type = "javax.sql.DataSource" />

2. Partial connection pool configuration (recommended)
At $ TOMCAT_HOME $ / conf / Catalina / localhost / directory create a new xml file, the xml file should be released with your Web application directory name the same, if for webappname.xml, add the following (configured Tomcat external virtual directory is at get here, and ha!)
<Context path = "/ webappname" docBase = "d: / webappname" debug = "0"
reloadable = "true" crossContext = "true">
<Resource
name = "jdbc / poolName"
auth = "Container"
type = "javax.sql.DataSource"
maxActive = "100"
maxIdle = "30"
maxWait = "10000"
username = "sa"
password = "password"
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
url = "jdbc: jtds: sqlserver: / / localhost: 1433; DatabaseName = pubs" />
<ResourceLink global = "jdbc / poolName" name = "jdbc / poolName"
type = "javax.sql.DataSource" />
</ Context>

Configure Tomcat \ webapps \ webappname \ WEB-INF \ web.xml, set reference source
<resource-ref>
<description> my DB Connection </ description>
<res-ref-name> jdbc / poolName </ res-ref-name> the same as server.xml
<res-type> javax.sql.DataSource </ res-type>
<res-auth> Container </ res-auth>
</ resource-ref>
Configuration \ Tomcat \ webapps \ webappname \ META-INF \ context.xml, the data source connection settings are as follows:
<? xml version ='1 .0 'encoding =' utf-8 '?>
<Context path = "/ webappname" docBase = "webappname" debug = "5"
reloadable = "true" crossContext = "true">
<ResourceLink name = "jdbc / poolName" global = "jdbc / poolName"
type = "javax.sql.DataSource" />
</ Context>

Context ctx = (Context) new InitialContext (). Lookup ( "java: comp / env");
DataSource ds = (DataSource) ctx.lookup ( "jdbc / poolName);
Connection conn = ds.getConnection ();
conn.close ();

Do not forget to call on the Connection object close () method, note: here will not turn off the
Connection, but will be back on the Connection Database Connection Pool.

-------------------------------------------------- ----------------------------------
Also can be injected into ways to call the connection pool, that is, in Hibernate configuration file hibernate.cfg.xm l call in the JSP container configured connection pool later, and then in the Hibernate configuration file called the system connection pool settings, the key code are summarized below:

<session-factory>
<! --
<property name="jndi.class"> </ property>
<property name="jndi.url"> </ property>
->
<property name="connection.datasource"> java: comp / env / jdbc / poolName </ property>
<property name="show_sql"> false </ property>
<property name="dialect"> org.hibernate.dialect.SybaseDialect </ property>
</ session-factory>

Hibernate specific use, please refer to the relevant detailed information.