connection pool:
(1) Traditional the JDBC:
①Class.forName () // load drivers
②Connection the DriverManager.getConnection Conn = (URI, User, pwd); // this method is connected to the database
③PreparedStatement pstmt = conn.preparedStatement (); // perform deletions change search
(2) the use of a core connection pool (from the upper level, using): The point to point connection from the database data source (the DataSource)
①DataSource ds = ......; // find ways to get the data source but the method ds not unique
②Connection ds.getConnection Conn = (); // this method is connected to the data source
③PreparedStatement pstmt = conn.preparedStatement (); // check performed deletions change
DBCP database connection pool mainly rely on:
The package commons-dbcp-1.4.jar
2 classes provided: of BasicDataSource and BasicDataSourceFactory second election to get one data source ds
①BasicDataSource ( hard-coded ):
Core methods:
DBCP way to get the data source steps:
②BasicDataSourceFactory ( using configuration: .properties file ):
Create a profile steps: Under Project src → New → File → dbcpconfig.properties
Note: Writing Profiles are key-value way
C3P0 connection pool database mainly rely on:
:
A core class provided: ComboPooledDataSource
C3P0 hardcoded in the DBCP and profile combined mode
Constructor and distinguished by the presence or absence of ComboPooledDataSource parameters:
No Reference: HARD
There are residual parameters: the configuration file (by default named official: c3p0-config.xml)
Hard-coded:
Profiles way: