Tomcat5 configure the Mysql JDBC database connection pool

Source: Internet
Author: User
Tags auth tomcat tomcat server
If you are only interested in MySql, you can copy this short article. If you want to configure a connection pool of other database types, you can also simply modify the parameters to use it.
1. Install Tomcat
Refer to the installation wizard of Tomcat for window to install Tomcat directly. Note: During installation, you will be prompted to enter the management user name and password, which will be used in the future. Remember.
2. Install MySql
By default.
3. Use Tomcat Web to manage applications and configure data sources
Start the Tomcat server, open the browser, and enter http: // localhost: 8080/admin/(localhost may be the IP address or server name of a machine) to go to the login page of the management interface, in this case, enter the user name and password required during the original installation and log on to the management interface,
Select Resources-Data sources to go to the Data Source configuration page. Select Data Source Actions-> Create New Data Source to go to the configuration details page. The content is as follows:
JNDI Name: jdbc/mysql
Data Source URL: jdbc: mysql: // 192.168.0.16/SUBRDB
JDBC Driver Class: org. gjt. mm. mysql. Driver
User Name: root
Password :********
Max. Active Connections: 4
Max. Idle Connections: 2
Max. Wait for Connection: 500
Validation Query:
The required information, such as the JNDI Name, can be entered based on your needs, except JDBC DriverClass. For example, the content of the Data Source URL may be: jdbc: mysql: // IP or name/DataBaseName, where DataBaseName is your database name, the IP address is the IP address or name of the server where your database is located. Finally, click Save-> Commit Change. In this way, the basic data of your data source is half configured.
4. Modify the referenced configuration file in web. xml and % TOMCAT_HOME % confCatalinalocalhost
Navigate to % TOMCAT_HOME % conf in the folder, open web. xml, and add the following content before </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>
Note that the res-ref-name must be the same as the JNDI Name mentioned above.
Navigate to % TOMCAT_HOME % confCatalinalocalhost in the folder, find the. xml file corresponding to your web application, such as ROOT. xml, and add code under this file:
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.