Tomcat 5.0-5.5 Connection Pool Configuration Guide

In this paper, the most popular MySQL, for example, explain the Tomcat connection pool through the basic steps to connect MySQL database, if you know MySQL can skip the first step.

Tomcat connection pool configuration before making first unzip, will be one of the mysql-connector-java-3.xx-xxx.jar removed, placed in \ common \ lib in.

Next, let us into the exciting journey Tomcat configuration.

1. New user and the database follow these steps:

C: \ Documents and Settings \ Administrator> d:

D: \> cd mysql \ bin

D: \ MySQL \ bin> mysql-u root-p
Enter password: *******
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 51 to server version: 4.1.12a-nt

Type 'help;' or '\ h' for help. Type '\ c' to clear the buffer.

mysql> GRANT ALL PRIVILEGES ON jcc .* TO jcc @ localhost IDENTIFIED BY ''
Query OK, 0 rows affected (0.01 sec)

mysql> USE mysql;
Database changed
mysql> SELECT Host, User, Password FROM user;
+-----------+------+------------------------------ -------------+
| Host | User | Password |
+-----------+------+------------------------------ -------------+
| Localhost | root | * 60D5B730382EC2170CA366DE181767E4C5343DE8 |
|% | Jsp | * C22AB0FD8A289C7D337C9998B63B8EA8335E5F35 |
| Localhost | jcc | * C22AB0FD8A289C7D337C9998B63B8EA8335E5F35 |
+-----------+------+------------------------------ -------------+
3 rows in set (0.01 sec)

mysql> exit

D: \ MySQL \ bin> mysql-u jcc-p
Enter password: **********
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 57 to server version: 4.1.12a-nt

Type 'help;' or '\ h' for help. Type '\ c' to clear the buffer.

Query OK, 1 row affected (0.02 sec)

mysql> USE jcc;
Database changed
mysql> CREATE TABLE user (
- ");
Query OK, 0 rows affected (0.08 sec)

mysql> INSERT INTO user (name) VALUES ('Corebit');
Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO user (name) VALUES ('Ivan');
Query OK, 1 row affected (0.03 sec)

mysql> SELECT * FROM user;
| Id | name |
| 1 | Corebit |
| 2 | Ivan |
2 rows in set (0.00 sec)


2. Tomcat5.0 configure Tomcat connection pool configuration as follows:

In the \ conf \ server.xml to add the following code in between ...:

factory org.apache.commons.dbcp.BasicDataSourceFactory

maxActive 100

maxIdle 30

maxWait 10000

username jcc


driverClassName com.mysql.jdbc.Driver

url jdbc: mysql: / / localhost / jcc

Tomcat5.5 to the following configuration:

In the \ conf \ server.xml to add the following code in between ...:

3. In the up / down, the new MySQL database connection file Select.jsp

Select.jsp source as follows:

"); While ( ()) (out.print (rs.getString (1) +" "); out.print (rs.getString (2) +"
");) Rs.close (); stmt.close (); conn.close ();) catch (Exception e) (out.print (e );}%>

4. Run http://localhost/Select.jsp, show the following results:

1 Corebit
2 Ivan

Said database connection success! Congratulations! Congratulations!

Otherwise, please check the version of the database connector, error probability is relatively high!

* Note:

Tomcat connection pool, some parameters as follows:

maxActive = "100"

maxIdle = "30"

maxWait = "10000"

jdbc: mysql: / / localhost / jcc

PS: If the maximum number of connections active in the database is too large, can be imagined, the memory footprint is very amazing! If the number of idle connections is too large, then the resource utilization rate, connection pooling is not a long-term release, can lead to abnormal connection pool node. So choose the right maxActive and maxIdle connection pool performance is a key factor, of course, depending on the server environment.

* Attachment:

Connection pooling principle of operation:

In the actual application development, particularly in the WEB application system, if JSP, Servlet or EJB Use JDBC directly access data in the database, every data access requests must be through the establishment of a database connection, open the database, access to data and shut down the database connection and other steps, the connection and open the database is a not only consume resources and time-consuming work, if the frequent occurrence of this database operations, system performance will inevitably drop sharply, or even cause system crashes. Database connection pool technology to solve this problem most commonly used method in many application server (for example: Weblogic, WebSphere, JBoss), the basic offer the technology without their own programming, but in-depth understanding of the technology is necessary.

Database connection pool technology's ideas are very simple, the database connection as an object stored in a Vector Duixiang in, once the database after the connection is established, different database access Qing Qiujiu can share Zhexie connections so that, through reuse these Yijing to establish the database connection, can overcome these shortcomings, significant savings in system resources and time.

The main operation of the database connection pool as follows:

(1) establishing a database connection pool object (the server starts).

(2) in accordance with the predetermined number of parameters to create the initial database connection (ie: the number of idle connections).

(3) for a database access request, directly from the connection pool to get a connection. If the database connection pool object in the connection is not idle, and there is no maximum number of connections (ie: the maximum number of active connections), to create a new database connection.

(4) access to the database.

(5) Close the database, the release of all the database connection (close the database connection at this time, not really close, but put it in the idle queue. If the actual number of idle connections is greater than the initial number of idle connections release connection).

(6) the release of the database connection pool object (the server stops, maintenance period, the release of the database connection pool object, and release all connections).

I hope this can you use Tomcat connection pool to connect MySQL database help!

Articles from leading network test software testing

分类:Java 时间:2010-09-16 人气:191
blog comments powered by Disqus


  • Documents and Settings Folder Redirection other letter 2010-06-30

    The network have a lot of movement on the Documents and Settings ways. There are several ways about A modified configuration file to install the operating system is 2 to modify the registry after installing the operating system 3 Using mountvol metho

  • JPA + Hibernate's connection pool settings C3P0.Proxool 2010-08-09

    1, Proxool configuration 1, the configuration file persistence.xml 1. <?xml version="1.0" encoding="UTF-8"?> 2. <persistence version="1.0" xmlns="" xmlns:xsi="http

  • hibernate configuration data source. hibernate - Database Connection Pool 2009-04-30

    In order to configure their own testing environment, and required their entire framework of the abstract, the introduction of the test framework, the tests have their own test cases. Database connection pool but found the old problems, questions and

  • Hibernate connection pool set up three C3P0.Proxool and DBCP 2009-05-07

    Hibernate connection pool set up three C3P0, Proxool and DBCP keyword: proxool, c3p0, dbcp <propertyname="connection.driver_class"> com.mysql.jdbc.Driver </ property> <propertyname="connection.url"> jdbc : mysql: / /

  • Tomcat connection pool configured in MySql 2010-06-06

    As directly edit the server.xml configuration connection pool is prone to error, I guess tomcat version of the problem, not a version may have slightly different configuration, so I recommend using the data source in http://localhost/admin/ configura

  • proxool connection pool 2010-10-21

    Proxool connection pool is an open source project under sourceforge, the project provides a robust, easy to use connection pooling, the most critical is the connection pool to provide monitoring capabilities, easy to use, easy to find connection leak

  • java database connection pool configured in several ways 2011-01-03

    Java database connection pool configuration on several ways to meet today on the data source connection pool configuration questions, find there are many ways to configure, are summarized as follows, (has Mysql database as an example) A, Tomcat confi

  • A similar DBCP data source (connection pool) and implementation (on) 2010-04-30

    During this time, is learning Hibernate, in the learning process, go back and go over JDBC, considerable gains. In fact, long time ago (sophomore), in contact with JDBC, and just felt very simple, and probably time for the software development was qu

  • IV. Tomcat5 to configure the connection pool and data source 2010-10-06

    1, DataSource interface, introduced (1) DataSource Overview JDBC1.0 they are used DriverManager class to create a data source. JDBC2.0 use an alternative approach, using the DataSource implementation, the code becomes more compact, more easily contro

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.166 (s). 10 q(s)