Reference: [problem] database connection pool
There are a lot of configuration methods on the Internet. I only record my configuration successful
1. Create context. xml in the META-INF folder of your web application as follows
<? XML version ="1.0"Encoding ="UTF-8"?>
<Context Path ="/Appname"Docbase ="Appname"
DEBUG ="5"Crosscontext ="True"Reloadable ="False"
Cachingallowed ="True"Cachemaxsize ="20480"
Cachettl ="10000">
<Resource Name ="JDBC/MySQL"Auth ="Container"Removeabandoned ="True"
Removeabandonedtimeout ="60"Logabandoned ="True"
Type ="Javax. SQL. datasource"Maxactive ="50"Maxidle ="10"
Maxwait ="10000"Username ="Root"Password ="Root"
Driverclassname ="Com. MySQL. JDBC. Driver"
Url ="JDBC: mysql: // localhost: 3306/dbname? Autoreconnect = true"/>
</Context>
Change the parameter name.
2. Add the following content to Web. xml:Code, Declare the use of external resources (the resource-ref location should be pretty low, I threw it at the end)
<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>
3. Pull the JDBC driver package to the Web lib (My mysql-connector-java-5.1.15-bin.jar)
Restart the server to obtain the connection.
Context context =NewInitialcontext ();
Datasource DS = (datasource) Context. Lookup ("Java: COMP/ENV/jdbc/MySQL");
Conn = Ds. getconnection ();