How to obtain the Tomcat connection pool MySQL

Source: Internet
Author: User

Open the context. xml file in the conf folder of Tomcat 6.0 and write it under the <context reloadable = "true"> label.

 
<Resource Name = "JDBC/mysqlds" auth = "Container" type = "javax. SQL. datasource "maxactive =" 100 "maxidle =" 30 "maxwait =" 10000 "username =" root "Password =" admin "driverclassname =" com. mySQL. JDBC. driver "url =" JDBC: mysql: // 127.0.0.1/blog "/>

And put the driver jar package in the Lib folder under Tomcat 6.0, and then use this section in the Java classCodeObtain:

 
Datasource DS = NULL; try {// use the context. xml file to set the name of the data source object and obtain the data source object. Context context = new initialcontext (); DS = (datasource) context. lookup ("Java:/COMP/ENV/jdbc/mysqlds");} catch (exception e) {system. out. println ("Database Retrieval error");} connection conn = Ds. getconnection ();

 

Then, use the queryrunner class:

Sqlqueryrunner QR = new queryrunner (DS); int result = QR. update (Conn, SQL, string []); // QR. update (SQL, string []); // call its update method to run the SQL statement and return the number of updates. insert into/update/delete list <blog> List = QR. query (SQL, new beanlisthandler (blog. class); // query. Blog. Class is JavaBean: blog. java. Stored in list.

 

@@@

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.