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.