Configure MySQL database connection pool _ MySQL under Tomcat

Source: Internet
Author: User
1. add the configuration information in $ CATALINA_HOMEconfserver.xml and declare the specific information of the connection pool. the added content is as follows :! -- Declare the connection pool -- ResourcenamejdbcmysqlauthContainertypejavax. SQL. DataSource Tomcat


1. add the configuration information in $ CATALINA_HOME/conf/server. xml to declare the specific information of the connection pool. add the following content:
  
  
  
  
  
  
  
  
  
  
  
   Factory
  
   Org. apache. commons. dbcp. BasicDataSourceFactory
  
  
  
  
  
   MaxWait
  
   5000
  
  
  
  
  
   MaxActive
  
   20
  
  
  
  
  
   Username
  
   Shopadm
  
  
  
  
  
   Password
  
   123
  
  
  
  
  
   Url
  
   Jdbc: mysql: // localhost/shopdb? UseUnicode = true & charact-erEncoding = gb2312
  
  
  
  
  
   DriverClassName
  
   Com. mysql. jdbc. Driver
  
  
  
  
  
   MaxIdle
  
   10
  
  
  
  
  
2. in $ CATALINA_HOME/conf/web. xmlAdd the following information before:
  
  
  
   DB Connection
  
   Jdbc/mysql
  
   Javax. SQL. DataSource
  
   Container
  
  
  
Where The parameter name must be the same as the connection name 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:
  
  
  
...
  
  
  
...
  
  
  
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. In To declare a database connection pool:
  
  
  
  
  
  
  
   Factory
  
   Org. apache. commons. dbcp. BasicDataSourceFactory
  
  
  
  
  
   MaxWait
  
   5000
  
  
  
  
  
   MaxActive
  
   20
  
  
  
  
  
   Password
  
   123
  
  
  
  
  
   Url
  
   Jdbc: mysql: // localhost/shopdb? UseUnicode = true & characterEncoding = gb2312
  
  
  
  
  
   DriverClassName
  
   Com. mysql. jdbc. Driver
  
  
  
  
  
   MaxIdle
  
   10
  
  
  
  
  
   Username
  
   Shopadm
  
  
  
  
  
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:
  
  
  
     
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">
  
  
  
   DB Connection
  
   Jdbc/mysql
  
   Javax. SQL. DataSource
  
   Container
  
  
  
  
  
The key is the italic part, pointing to the previously stated 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.