Tomcat connection pool configuration code (including tomcat5.0, tomcat5.5x, and tomcat6.0)

Source: Internet
Author: User

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: CopyCode The Code is as follows: <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" type = "codeph" text = "/codeph"/>

2. configure the web under your application. add between XML: copy Code the code is as follows:
dB connection
JDBC/Oracle
javax. SQL. datasource
container

3. put the Third-Party driver that connects to the database under common/lib.
4. test the Program . I will not write the
atat5.5x connection pool configuration
method 1. Global Database Connection Pool
1. Management interface Configuration connection pool, or directly go to Tomcat \ conf \ Server. add copy Code the code is as follows: 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:Copy codeThe Code is as follows: <resourcelink global = "JDBC/mydb" name = "JDBC/mydb" type = "javax. SQL. datasource"/>

Method 3: Local Database Connection Pool
Add the following in the context of Tomcat \ webapps \ myapps \ META-INF \ context. xml:Copy codeThe Code is 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 "/>

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 under the Tomcat path (Tomcat \ conf \ Catalina \ localhost). The content is as follows: Copy code The Code 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. basicperformancefactory </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 cballs 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
Mm. MySQL JDBC driver will automatically reconnect if mysqld closed
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.