Tomcat configuration connection pool (MySQL database)

Source: Internet
Author: User

Add the following to the <context> node in the tomcat_home/CONF/context. xml file:

<Resource
Name = "JDBC/SQL"
Auth = "Container"
Type = "javax. SQL. datasource"
Maxactive = "100"
Maxidle = "30"
Maxwait = "10000"
Username = "root"
Password = "root"
Driverclassname = "com. MySQL. JDBC. Driver"
Url = "JDBC: mysql: // localhost: 3306/test"
/>

Attribute explanation:

Name: Data Source Name Auth: Permission type: Type

Maxactive: Maximum number of connections to the database. Set 0 to no limit.

Maxidle: Maximum number of waiting connections. Set 0 to no limit.

Maxwait: Maximum number of waiting milliseconds, measured in MS, error messages are generated when the time exceeds

 

Add

<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/SQL </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>

 

 

Obtain the connection method in the project:

context initcontext = new initialcontext ();
context envcontext = (context) initcontext. lookup ("Java:/COMP/ENV");
datasource DS = (datasource) envcontext. lookup ("JDBC/SQL");
connection conn = Ds. getconnection ();
statement ST = NULL;
resultset rs = NULL;
ST = Conn. createstatement ();
rs1_st.exe cutequery (SQL);

Related Article

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.