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)