I. Encapsulating the database connection (similar to DBCP)
1. Download
Https://sourceforge.net/projects/c3p0/?source=typ_redirect
2. Import jar
Mchange-commons-java-0.2.11.jar C3p0-0.9.5.2.jar
3, write the configuration file C3p0-config.xml
<?XML version= "1.0" encoding= "UTF-8"?><C3p0-config> <!--This app is massive! - <Named-configname= "C3p0"> < Propertyname= "User">Root</ Property> < Propertyname= "Password">Root</ Property> < Propertyname= "Driverclass">Com.mysql.jdbc.Driver</ Property> < Propertyname= "Jdbcurl">jdbc:mysql://127.0.0.1:3306/hibernate</ Property> <!--How many connections to a database at a time if the database connection is insufficient - < Propertyname= "Acquireincrement">5</ Property> < Propertyname= "Initialpoolsize">5</ Property> < Propertyname= "Minpoolsize">5</ Property> < Propertyname= "Maxpoolsize">10</ Property> </Named-config></C3p0-config>
4. Write test
@Test Public void testc3p0 () { new combopooleddatasource ("c3p0"); Try { System.out.println (ds.getconnection ()); Catch (SQLException e) { e.printstacktrace (); } }
C3P0 Database Connection Pool