1. Guide Package
2, Configuration C3p0-config.xml
<?XML version= "1.0" encoding= "UTF-8"?><C3p0-config> <Default-config> < Propertyname= "Driverclass">Com.mysql.jdbc.Driver</ Property> < Propertyname= "Jdbcurl">jdbc:mysql:///table name? usessl=true</ Property> < Propertyname= "User">User name</ Property> < Propertyname= "Password">Password</ Property> < Propertyname= "Initialpoolsize">5</ Property> < Propertyname= "Maxpoolsize">20</ Property> </Default-config> <Named-configname= "Oracle"> < Propertyname= "Driverclass">Com.mysql.jdbc.Driver</ Property> < Propertyname= "Jdbcurl">jdbc:mysql:///table name? usessl=true</ Property> < Propertyname= "User">User name</ Property> < Propertyname= "Password">Password</ Property> </Named-config> </C3p0-config>
3. Create C3p0utils Class
Packagec3p0utils;Importjava.sql.Connection;Importjava.sql.SQLException;ImportJavax.sql.DataSource;ImportCom.mchange.v2.c3p0.ComboPooledDataSource; Public classC3p0utils {Private StaticCombopooleddatasource DataSource =NewCombopooleddatasource (); Public StaticDataSource Getdatasource () {returnDataSource; } Public StaticConnection getconnection () {Try { returndatasource.getconnection (); } Catch(SQLException e) {Throw NewRuntimeException (e); } }}
Using C3P0 and Dbutils