Tomcat5 Configures Mysql JDBC Database Connection Pool (Modified Version)

xiaoxiao2021-03-06  63

If you just interested in mysql, you can use this short message. If you want to configure the connection pool of other database types, you can also use simple modification parameters. 1. Install the Tomcat for Window's installation wizard, basically directly installed, Note: Enter the management username and password when installing, this is the username and password that will be used later, remember. 2, install MySQL default installation. 3, use Tomcat's Web Management App to Configure the data source to start the Tomcat server, open the browser, enter http: // localhost: 8080 / admin / (where localhost may be a machine's IP or server name), enter the management interface Log in page, at this time, please enter the username and password required to enter the original installation, log in to the management interface, select Resources-Data Sources to enter the configuration data source interface, select Data Source Actions -> Select CREATE New Data Source, enter the configuration details interface 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 information requested by JNDI Name is required, in which other other can be filled in according to your needs. For example, the content of the Data Source URL may be: jdbc: mysql: // ip or name / databasename, where DatabaseName is your database name, IP is the IP or name of the server where your database is located. Finally click Save-> Commit Change. So your basic data of your data source is half configured. 4, web.xml and% tomcat_home% / conf / catalina / localhost, corresponding to your reference configuration file modification to navigate through the folder to% tomcat_home / conf, open web.xml, add it in front of The following: DB connection jdbc / mysql javax.sql.datasource Container Note The content completed by RES-REF-NAME is consistent with the JNDI Name name mentioned above. Under the folder navigation to% tomcat_home / conf / Catalina / localhost, find the .xml file corresponding to your web application, such as root.xml, and add the code below this file: here, the configuration work is basically completed. 5. Other considerations Don't forget the JDBC driver mysql-connection-java-3.0.9-stable-bin.ja must be placed to Tomcat's corresponding directory, your JDBC driver may version is high, but as long as you can The mysql used is OK, because I found that the version of the JDBC driver cannot support 4.0. * Version of the MySQL database, it is recommended to place under the% Tomcat_Home% / COMMON / LIB and the application of Web-INF / LIB. What is the difference between the two? In fact, I will understand that Common / Li is all applications where all applications can be used. Restart your Tomcat service.

6. Writing test code builds a test.jsp file in the application's directory, the code is as follows: <% @ page import =" java.sql. * "%> <% @ Page import =" javax.sql. * "%> <% @ Page import =" javax .naming. * "%> <% @ Page session =" false "%> > Run results: My test starts 12345678 My test ends because my RS.Getstring (1) is stored in the database 12345678

7. Summary the configuration process and its simply clear, these configurations are exempt from the past developers to write the data source connection pool, which is also a strong support for the development process.

转载请注明原文地址:https://www.9cbs.com/read-111282.html

New Post(0)