Tomcat configuration database connection pool

xiaoxiao2021-03-06  74

I.Server.xml configuration data source:

factory org.apache.commons.dbcp.basicdataasourcefactory

maxactive 100 maxidle < Value> 30 maxwait 10000 Username dbuser password 1234

driverclassname com.mysql.jdbc.driver URL jdbc: mysql: // localhost: 3306 / BOOKDB? Autoreconnect = true

Parameter Description: 1.Resource 1) Name Specifies the JDNI Name 2) Auth Specifies the management of the resource. There are two options Container and Application Container represents the container to create and manage the resource application representation by the web application. Creating and Managing Resource 3) Type Specifies the Java Class Name of Resource Associated 2.ResourceParam 1) Factory Specifies the Max Name of the Factory Generation DataSource to specify the maximum number of database connections in the database connection pool 3) MaxIdle specified database Maximum number of database connections in the connection pool 4) MaxWait Specifies the longest time in the database connection in the database connection pool. The unit is in milliseconds, which will throw an exception in this time. Take the value is -1 Represents the username that can be waited indefinitely 5) Username Specifies the connection database 6) Password specifies the password of the connection database 7) DRIVERCLASSNAME Specifies the JDBC driver for the connection database 8) URL Specifies the URL II .Web.xml Statement to JDNI References of Resource

DB Connection JDBC / BOOKDB Javax.sql.DataSource Container

Parameter Description: Description: Res-Ref-name: Specifies the JDNI history word of the reference resource, corresponding to the name word of the reference resource with the Name property in . Correspond to the TYPE attribute in Res-auth Specifies the administrator of the reference resource. Corresponds to the Auth in

II. Access Data Source 1) Find data sources, generate java.sql.datasoruce reference javax.nameing.context provides the interface of the JDNI Resource for the interface CONTEXT CTX = New InitialContext (); DataSource DS = (Datasource) CTX.lookup ("Java: Comp / env / jdbc / bookdb "); 2) Get the connection connection con = ds.getConnection ();

3) Turn off the connection con.close (); close () method, return the connection to the database connection pool, so that the Connection is restored to the short status of the four .JSP application example (omitted) 5. Compare JDBC

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

New Post(0)