Common Connection pool correlation (DBCP, C3P0)

Source: Internet
Author: User

DBCP: (Understanding)
Apache Organization
Steps to use:
1. Importing jar packages (Commons-dbcp-1.4.jar and Commons-pool-1.5.6.jar)
2. Using the API

1 //hard-coded2 //Create a connection pool3Basicdatasource ds =NewBasicdatasource ();4 5 //configuration Information6Ds.setdriverclassname ("Com.mysql.jdbc.Driver");7Ds.seturl ("Jdbc:mysql:///day07");8Ds.setusername ("root");9Ds.setpassword ("1234");Ten //configuration file One //implement writing a properties file A //Store configuration Files -Properties prop =NewProperties (); -Prop.load (NewFileInputStream ("Src/dbcp.properties")); the //Set - //prop.setproperty ("Driverclassname", "Com.mysql.jdbc.Driver"); -  - //Create a connection pool +DataSource ds =NewBasicdatasourcefactory (). CreateDataSource (prop);

C3P0: (★)
Hibernate and Spring use
There is the ability to automatically reclaim idle connections.
Steps to use:
1. Importing the jar package (C3p0-0.9.1.2.jar)
2. Using the API
A. Hard-coded (not recommended)
New Combopooleddatasource ()
B. Configuration files
Configuration file name: C3p0.properties or C3p0-config.xml
Path to the configuration file: src

The code only needs a word
New Combopooleddatasource ()//using the default configuration
New Combopooleddatasource (String configname)//Use a named configuration if the configured name is not found, use the default configuration

Common Connection pool correlation (DBCP, C3P0)

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.