DBCP Connection Pool

Source: Internet
Author: User

One, the required jar package

Commons-dbcp

Commons-pool

Second, Java code

1 @Test2      Public voidTestprop () {3Connection con =NULL;4         Try {5             //load the prop configuration file6Properties prop =NewProperties ();7             //Get file Stream8InputStream instream = app_dbcp.class. getResourceAsStream ("Db.properties");9             //loading the property configuration fileTen prop.load (instream); One             //Create a data source object directly based on the prop configuration ADataSource Datasouce =Basicdatasourcefactory.createdatasource (prop); -              -             //Get Connections theCon =datasouce.getconnection (); -Con.preparestatement ("Delete from admin where id=4"). executeupdate (); -}Catch(Exception e) { - e.printstacktrace (); +             Throw NewRuntimeException (e); -}finally { +             //Close A             if(Con! =NULL) at                 Try { - con.close (); -}Catch(SQLException e) { - e.printstacktrace (); -                     Throw NewRuntimeException (e); -                 } in         } -          to}

Ii. configuration Files (db.properties)

1 url=jdbc:mysql:///jdbc_demo2 driverclassname=com.mysql.jdbc.Driver  3 username=root4 password=root5 initialsize=36 Maxactive=67 maxidle=3000

DBCP 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.