Tomcat6.0 connection pool Configuration
1. Configure the context. xml file in the conf file under tomcat, and add the connection pool Configuration between them:
<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url=" jdbc:oracle:thin:@host:port:databse" username=" user " password="password" maxActive="100" maxIdle="30" maxWait="10000" />
2. Add the following content to the Web. xml file of your application:
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/oracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
3. Put the Third-Party driver connecting to the database under common/lib.
4. I will not write the test program.
Tomcat5.5x connection pool Configuration
Method 1: Global Database Connection Pool
1. Configure the connection pool through the management interface, or directly add
<Resource name="jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000" validationQuery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb" maxActive="4"/>
2. Add the following in the context of Tomcat/webapps/MyApp/META-INF/context. xml:
<ResourceLink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>
In this way, you can.
Method 2: Global Database Connection Pool
1. Same as above
2. Add the following content to the context of Tomcat/CONF/context. xml:
<ResourceLink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>
Method 3: Local Database Connection Pool
Just add the following to the context of Tomcat/webapps/myapps/META-INF/context. xml:
<Resource name="jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000" validationQuery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb" maxActive="4"/>
Parameter description:
Driveclassname: full name of the JDBC Driver Class;
Maxactive: Maximum number of available instances that can be allocated from the connection pool;
Maxidle: Maximum number of connections that can be idle in the connection pool at the same time;
Maxwait: Maximum timeout in milliseconds;
Password: user password;
URL: URL Connection to JDBC;
User: user name;
Validationquery: Used to query idle connections in the pool.
The preceding three methods can be used in Tomcat 5.5.4. In addition, the JDBC driver of SQL Server is the SQL Server JDBC (SP3) downloaded from the Microsoft website ).
Tomcat5.0 connection pool Configuration
Create an XML file in the path below Tomcat (tomcat/CONF/Catalina/localhost). The content is as follows:
<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/test"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. --> <parameter> <name>maxActive</name> <value>100</value> </parameter> <!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. --> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. --> <parameter> <name>maxWait</name> <value>10000</value> </parameter> <!-- MySQL dB username and password for dB connections --> <parameter> <name>username</name> <value>sa</value> </parameter> <parameter> <name>password</name> <value>test</value> </parameter> <!-- Class name for JDBC driver --> <parameter> <name>driverClassName</name> <value>net.sourceforge.jtds.jdbc.Driver</value> </parameter> <!-- Autocommit setting. This setting is required to make Hibernate work. Or you can remove calls to commit(). --> <parameter> <name>defaultAutoCommit</name> <value>true</value> </parameter> <!-- The JDBC connection url for connecting to your MySQL dB. The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. --> <parameter> <name>url</name> <value>jdbc:jtds:sqlserver://url/filedb;charset=gb2312;autoReconnect=true</value> </parameter> <!-- Recover abandoned connections --> <parameter> <name>removeAbandoned</name> <value>true</value> </parameter> <!-- Set the number of seconds a dB connection has been idle before it is considered abandoned. --> <parameter> <name>removeAbandonedTimeout</name> <value>60</value> </parameter> <!-- Log a stack trace of the code which abandoned the dB connection resources. --> <parameter> <name>logAbandoned</name> <value>true</value> </parameter> </ResourceParams>