Configure the database connection pool for MySQL and Tomcat (administrator interface)

Source: Internet
Author: User
Tags user definition

In the past few days, follow the existing tutorial on the Internet to combine MySQL and tomcat to configure the database connection pool. After a great deal of effort, I finally succeeded. There are two methods to configure the connection pool (Tomcat + MySQL): code configuration and visual configuration.
The visual configuration is convenient and quick. The following describes the configuration process based on my configuration experience.
Version: MySQL-4.19, Tomcat -- 5.5.9.
Before configuring the Tomcat connection pool, extract mysql-connector-java-xxx.zip and put the mysql-connector ctor-Java-3. X. x-xxx.jar in commonlib? Go to http://www.mysql.com/productsto download it.

1. if admin is not installed on Tomcat, install Admin first. After the installation with admin permission login (user management in/CONF/tomcat-user.xml, if there is no admin permission of the user, create a user, or set existing tomcat or both to roles = "admin ");
2. After logging in, you can see the following functions in the selection bar on the left:
-- Tomcat server
-- + Service (Catalina)
-- Resources
-- + Data sources
-- + Mail sessions
-- + Environment entries
-- + User Databases
-- User Definition
-- + Users
-- + Groups
-- + Roles
Click data sources --> data source actions and select create new data source from the drop-down list. Fill in the following options. yxz is the MySQL instance I created and can be modified as needed.
JNDI name: MySQL/yxz
Data source URL: JDBC: mysql: // localhost: 3306/yxz
JDBC Driver Class: COM. MySQL. JDBC. Driver
User name: Root
Password: Root
Max. Active connections: 20 --- maximum number of active connections
Max. idle connections: 10 --- maximum number of idle connections
Max. Wait for connection: 5000
Validation query:
After completion, press save, then Commit Changes, OK!
3. The visual configuration of the database connection pool is complete. However, if you want to use the connection pool under the corresponding application, you still need to configure the corresponding content. xml. Create the content. xml file in yourapp/META-INF/and copy the configuration as follows:

 



            factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
         driverClassName="com.mysql.jdbc.Driver"
         url="jdbc:mysql://localhost:3306/yxz"
         username="root" password="root"
         maxActive="20" maxIdle="10" maxWait="-1" />


Save, OK.
4. Create a table: User in yxz in MySQL for testing. The User table contains the field ID and name.
5. Test the program, create index. jsp under yourapp, and copy the following code:

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.