Tomcat Several connection pool configuration codes (including tomcat5.0,tomcat5.5x,tomcat6.0) _tomcat

Source: Internet
Author: User
Tags auth stack trace tomcat
Tomcat6.0 Connection Pool Configuration
1. Configure the Context.xml files under Tomcat under Conf to add a connection pool configuration between:
Copy Code code as follows:

<resource name= "Jdbc/oracle"
Auth= "Container"
Type= "Javax.sql.DataSource"
Driverclassname= "Oracle.jdbc.driver.OracleDriver"
Url= "Jdbc:oracle:thin: @host:p ort:databse"
Username= "User"
password= "Password"
Maxactive= "100"
Maxidle= "30"
maxwait= "10000"/>

2. Configure the Web.xml in your application to join:
Copy Code code as follows:

<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 drive connected to the database under Common/lib.
4. Test program I'm not going to write it.
tomcat5.5x Connection Pool Configuration
Mode one, global database connection pool
1, through the management interface to configure the connection pool, or directly in the Tomcat\conf\server.xml globalnamingresources increase
Copy Code code as follows:

<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, in the context of tomcat\webapps\myapp\meta-inf\context.xml increase:
<resourcelink global= "Jdbc/mydb" name= "Jdbc/mydb" type= "Javax.sql.DataSource"/>
That's it.
Mode two, global database connection pool
1, ditto
2, in the context of tomcat\conf\context.xml increase:
Copy Code code as follows:

<resourcelink global= "Jdbc/mydb" name= "Jdbc/mydb" type= "Javax.sql.DataSource"/>

Mode three, local database connection pool
Just add in the context of Tomcat\webapps\myapps\meta-inf\context.xml:
Copy Code code as follows:

<resource name= "Jdbc/mydb" type= "Javax.sql.DataSource" password= "MyPwd" 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:
The complete name of the Driveclassname:jdbc driver class;
Maxactive: The maximum number of available instances that can be allocated from the connection pool at the same time;
Maxidle: The maximum number of connections that can be idle at the same time in the connection pool;
Maxwait: Maximum timeout time, in milliseconds;
Password: User password;
URL: url to jdbc connection;
User: Name;
Validationquery: Used to query for idle connections in the pool.
All three of these methods are available under Tomcat 5.5.4. In addition, the JDBC driver for SQL Server is the SQL Server JDBC (SP3) that is downloaded from the Microsoft Web site.
tomcat5.0 Connection Pool Configuration
Under Tomcat's path (Tomcat \conf\catalina\localhost), an XML file is built with the following contents
Copy Code code 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
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 A DB connection to become available
In MS, example 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 are 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
Mm.mysql JDBC Driver'll 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.