Tomcat Configuration database Connection pool

Source: Internet
Author: User

The connection of database in Web development is necessary, and the database connection pool technology optimizes the connection between dynamic page and database, which saves a lot of resources compared to the connection pool of single connection database.

First, the Java connection to the MySQL database jar package is placed in the Lib directory of the Web project. second, all Tomcat projects share a connection pool configuration

    • in the Tomcat6->conf->context.xml file in which to add between <context></context>:

<Context>
<resource name= "Jdbc/mengshan"                auth= "Container"
type= "Javax.sql.DataSource"
Maxactive= "maxidel=" maxwait= "1000" username= "Root" password= "" driverclassname= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/molpoints" ></Resource>
</Context>
Username: The user name of the database password: The login password for the database. Driverclassname:java connect the first database, drivername are different. Here is the drivername;url for connecting to MySQL: Connection mode (JDBC/ODBC): Database type://Database IP Address: Database port number/database name such as:jdbc:mysql://localhost:3306/molpoints

    • <web-app></web-app> Add:

<web><resource-ref><res-ref-name>jdbc/mengshan </res-ref-name><res-type>javax.sql.datasource </res-type><res-auth>Container</res-auth></resource-ref></web>

third, each Web project independently with its own connection pool configuration
    • In the meta-inf of the project directory, create the Context.xml
<?xml version= "1.0" encoding= "UTF-8"?><context path= "/" >
<resource name= "MyDS"
type= "Javax.sql.DataSource"
driverclassname= "Com.mysql.jdbc.Driver"
maxidle= "2"
maxwait= "The
"
username= "root"
password= "123"
url= "Jdbc:mysql://localhost:3306/molpoints"
maxactive= "4"/>
<!--name:datasource name--
<!--type: the Java type of the data source, typically designed Javax.sql.DataSource--
<!--username: Database Login name
--
<!--password: Database login password
--
<!--driverclassname: Specify the database JDBC driver
--
<!--URL: Specify the URL of the database--
<!--maxidle: Maximum number of database connections in which the connection pool is idle, 0
for unrestricted-
<!--maxwait: The maximum time (in milliseconds) that a database connection in a connection pool is idle, taking 0 for unlimited wait time
-
<!--maxactive: Maximum number of connection pool active database connections, to 0 means
unrestricted-
</Context>
    • In the project, Web. XML joins
 <resource-ref
  <res-ref-name>jdbc/mengshan</res-ref-name>   <res-type>javax.sql.datasource</res-type>   <res-auth>container</res-auth>
&NBSP;</RESOURCE-REF>

Tomcat configuration database connection pool

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.