Tomcat JNDI Database Configuration connection pool Configuration

Source: Internet
Author: User

Add Resource in Tomcat 5.5/CONF/Catalina/localhost/XXXXX. XML (XXXXX. XML is your web configuration XML file)

<Resource Name = "MySQL"
Type = "javax. SQL. datasource"
Driverclassname = "com. MySQL. JDBC. Driver"
Password = "********"
Maxidle = "2"
Maxwait = "5000"
Username = "root"
Url = "JDBC: mysql: // localhost: 3306/jnestore"
Maxactive = "10"/>

The above is the configuration of Tomcat 5.5. Only in this way can Tomcat 5.5 be effective. Previous versions can be added as paramter;

Resource must be included between <context...> </context>

Find web. XML in your WEB-INF, add resource ing

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

Put MySQL JDBC driver. jar package in Tomcat common/lib down, you can also put in WEB-INF/lib,

Restart tomcat.

You can use context CTX = new initialcontext ();

Datasource DS = (datasource) CTX. Lookup ("Java: COMP/ENV/MySQL ");

Connection con = Ds. getconnection (); to connect to the 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.