First of all, you need to import the c3p0
package.c3p0
After downloading and decompressing, there are three packages in the lib
directory, use mysql If
, you only need to import c3p0-0.9.5.2.jar
,mchange-commons-java-0.2.11.jar
.
mysql database, you need to import
mysql-connector-java-5.1.42-bin.jar.
commons-dbutils-1.6.jar,
commons-collections-3.2.2.jar,
commons-logging-1.2.jar.
easy to maintain, c3p0-config.xml
<?xml version="1.0" encoding="UTF-8"?><c3p0-config> <default-config><property name="user">root</property><property name="password">root</property><property name="jdbcUrl">jdbc:mysql://127.0.0.1:3306/day20</property><property name="driverClass">com.mysql.jdbc.Driver</property> </default-config></c3p0-config>needs to be created in the src directory
import javax.sql.DataSource;import com.mchange.v2.c3p0.ComboPooledDataSource;public class JdbcUtils {private static ComboPooledDataSource ds;static { ds = new ComboPooledDataSource(); }public static DataSource getDataSource(){return ds; } }
The above is the detailed content of c3p0 usage record in java. For more information, please follow other related articles on the PHP Chinese website!