The connection of database in Web development is necessary, and the database connection pool technology optimizes the connection between dynamic page and database, which saves a lot of resources compared to the connection pool of single connection database.
First, the Java connection to the MySQL database jar package is placed in the Lib directory of the Web project. second, all Tomcat projects share a connection pool configuration
- in the Tomcat6->conf->context.xml file in which to add between <context></context>:
<Context>
<resource name= "Jdbc/mengshan" auth= "Container"
type= "Javax.sql.DataSource"
Maxactive= "maxidel=" maxwait= "1000" username= "Root" password= "" driverclassname= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/molpoints" ></Resource>
</Context> Username: The user name of the database password: The login password for the database. Driverclassname:java connect the first database, drivername are different. Here is the drivername;url for connecting to MySQL: Connection mode (JDBC/ODBC): Database type://Database IP Address: Database port number/database name such as:jdbc:mysql://localhost:3306/molpoints |
<web><resource-ref><res-ref-name>jdbc/mengshan </res-ref-name><res-type>javax.sql.datasource </res-type><res-auth>Container</res-auth></resource-ref></web> |
third, each Web project independently with its own connection pool configuration
- In the meta-inf of the project directory, create the Context.xml
<?xml version= "1.0" encoding= "UTF-8"?><context path= "/" >
<resource name= "MyDS"
type= "Javax.sql.DataSource"
driverclassname= "Com.mysql.jdbc.Driver"
maxidle= "2"
maxwait= "The
"
username= "root"
password= "123"
url= "Jdbc:mysql://localhost:3306/molpoints"
maxactive= "4"/>
<!--name:datasource name--
<!--type: the Java type of the data source, typically designed Javax.sql.DataSource--
<!--username: Database Login name
--
<!--password: Database login password
--
<!--driverclassname: Specify the database JDBC driver
--
<!--URL: Specify the URL of the database--
<!--maxidle: Maximum number of database connections in which the connection pool is idle, 0
for unrestricted-
<!--maxwait: The maximum time (in milliseconds) that a database connection in a connection pool is idle, taking 0 for unlimited wait time
-
<!--maxactive: Maximum number of connection pool active database connections, to 0 means
unrestricted-
</Context>
|
- In the project, Web. XML joins
<resource-ref
<res-ref-name>jdbc/mengshan</res-ref-name> <res-type>javax.sql.datasource</res-type> <res-auth>container</res-auth>
&NBSP;</RESOURCE-REF> |
Tomcat configuration database connection pool