Configure the MySQL database connection pool in Tomcat

Source: Internet
Author: User
Tags apache tomcat

Configure the MySQL database connection pool in Tomcat [Author: alias post: It lab hits: 11149 updated:]

1. Add the configuration information in $ catalina_home/CONF/server. XML to declare the specific information of the connection pool. Add the following content:

<! -- Declare the connection pool --> <Resource Name = "JDBC/MySQL" auth = "Container" type = "javax. SQL. datasource"/> <! -- Set the connection pool parameters --> <resourceparams name = "JDBC/MySQL">

<Parameter> <Name> factory </Name> <value> org. Apache. commons. DBCP. basicdatasourcefactory </value>

</Parameter>

<Parameter>

<Name> maxwait </Name>

<Value> 5000 </value>

</Parameter>

<Parameter>

<Name> maxactive </Name>

<Value> 20 </value>

</Parameter>

<Parameter>

<Name> username </Name>

<Value> shopadm </value>

</Parameter>

<Parameter>

<Name> password </Name>

<Value> 123 </value>

</Parameter>

<Parameter>

<Name> URL </Name>

<Value> URL </value>

</Parameter>

<Parameter>

<Name> driverclassname </Name>

<Value> com. MySQL. JDBC. Driver </value>

</Parameter> <parameter>

<Name> maxidle </Name>

<Value> 10 </value>

</Parameter>

</Resourceparams>

2. Add the following information before $ catalina_home/CONF/Web. xml </Web-app>:

<Resource-ref>

<Description> dB connection </description>

<Res-ref-Name> JDBC/MySQL </RES-ref-Name>

<Res-type> javax. SQL. datasource </RES-type>

<Res-auth> container </RES-auth>

</Resource-ref>

The parameter names in <res-ref-Name> must be the same as the connection names declared in server. xml.

3. Find the configuration information of the current program for database connection in the $ catalina_home/CONF/Catalina/localhost directory, for example, shopping. xml. Add the following information to this file:

<Context…> ...

<Resourcelink name = "JDBC/MySQL" Global = "JDBC/MySQL" type = "javax. SQL. datasource"/>

</Context>

Success!

On this basis, refer to the user manual on the official Tomcat website to find another method for configuring the connection pool. modify the XML. You only need to modify the configuration document of the program that needs to be used in the connection pool.

The method is as follows:

1. In the $ catalina_home/CONF/Catalina/localhost directory, find the configuration document of the program for the database connection pool. Here is shopping. xml.

Add the following information between <context> </context> to declare a database connection pool:

<Resource Name = "JDBC/MySQL" auth = "Container" type = "javax. SQL. datasource"/>

<Resourceparams name = "JDBC/MySQL">

<Parameter>

<Name> factory </Name>

<Value> org. Apache. commons. DBCP. basicperformancefactory </value>

</Parameter>

<Parameter>

<Name> maxwait </Name>

<Value> 5000 </value>

</Parameter>

<Parameter>

<Name> maxactive </Name>

<Value> 20 </value>

</Parameter>

<Parameter>

<Name> password </Name>

<Value> 123 </value>

</Parameter>

<Parameter>

<Name> URL </Name>

<Value> JDBC: mysql: // localhost/shopdb? Useunicode = true & characterencoding = gb2312 </value> </parameter> <Name> driverclassname </Name> <value> COM. mySQL. JDBC. driver </value> </parameter> <Name> maxidle </Name> <value> 10 </value> </parameter> <Name> username </Name> <value> shopadm </value> </parameter> </resourceparams>

The parameters here are almost the same as the information added to server. XML in the previous method.

2. Create a web. XML document under the WEB-INF of the corresponding program and add the following information:

<? XML version = "1.0" encoding = "ISO-8859-1"?>

<Web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version = "2.4">

<Resource-ref>

<Description> dB connection </description>

<Res-ref-Name> JDBC/MySQL </RES-ref-Name>

<Res-type> javax. SQL. datasource </RES-type>

<Res-auth> container </RES-auth>

</Resource-ref>

</Web-app>

Other references:

Http://www.jaxmao.org/tomcat-docs/jndi-resources-howto.html

Apache Tomcat 5.5 Chinese API

Related Article

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.