Tomcat Database Connection Pool

Source: Internet
Author: User
Tags auth connection pooling

As a result of the project needs, the use of Tomcat connection pool, from the Internet to check a lot of content, according to the content of the man step, or there is a problem, and finally see the official example to find the correct method.

Website Link: http://tomcat.apache.org/tomcat-8.5-doc/jndi-resources-howto.html

Tomcat version: apache-tomcat-8.5.15

1. Copy the MySQL connection pack Mysql-connector-java-5.1.41-bin.jar file to the Tomcat Lib folder.

2, under the Web application, Meta-inf folder under the new Context.xml, (refer to Tocat context.xml, copy the head of the tail), add

<resource
Name= "Jdbc/t1"
Auth= "Container"
Type= "Javax.sql.DataSource"
maxtotal= "100"
Maxidle= "30"
Maxwaitmillis= "10000"
Username= "Tomcat"
Password= "123456"
Driverclassname= "Com.mysql.jdbc.Driver"
Url= "Jdbc:mysql://localhost:8080:3306/t1"
/>

3, under the WEB application, Web-inf folder under the XML file add:

<resource-ref>
<description>db connection</description>
<res-ref-name>jdbc/t1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4. Deploy Web Apps to Tomcat, launch Tomcat, no alarms.

5. Applying in code

Context C = new InitialContext ();
DataSource ds = (DataSource) c.lookup ("Java:comp/env/jdbc/t1");
conn = Ds.getconnection ();

The benefits of using connection pooling are:

1, the database operation performance has been improved;
2, through the connection pool management database connection and release, improve the use of system resources efficiency;

Tomcat Database Connection Pool

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.