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
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Tomcat 5.0-5.5 Connection Pool Configuration Guide

  • ror development environment to build

    Ror about the development environment set up, records are as follows. 1. Netbeans6.5 installation download netbeans6.5 address Ruby can download a separate version that only around 50M. II. Ruby set up the e ...

  • SqlServer database connection pool to connect tomcat

    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 co ...

  • JPA data source data source to configure Tomcat conversion essay questions

    To the JPA in the use of the development process, sometimes used in the data source conversion problem, The following methods are only my personal experience of a situation and its solutions, if different, please everyone posted for your reference encount

  • Spring + Hibernate to use Glassfish Database Connection Pool

    applicationContext.xml file content <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = " " xmlns: xsi = " " ...


    dsfdsa Tomcat 6 with the connection pool data source configuration project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • Hibernate.cfg.xml configuration file (including the primary key generation strategy Introduction)

    Hibernate.cfg.xml configuration file: <? xml version = "1.0" encoding = "utf-8"?> <! DOCTYPE hibernate-configuration PUBLIC "- / / Hibernate / Hibernate Configuration DTD / / EN" "hibernate-configuration-2.0.dtd

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • spring struts2.0 hibernate environmental structures .. despair carried out more than one hour only with good. Look here. . Note added myeclipse support spring when necessary add the commons-dbcp database connection pool package. And to add hibernate support. . Finally add struts2 support. . Oh the lazy point. . . fu

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries