gistfile1.txt package com.cn.utils;import javax.sql.DataSource;import com.mchange.v2.c3p0.ComboPooledDataSource;//c3p0 会自动读取c3p0-config.xml文件(默认放在class目录下,会被自动读取)public class C3P0Utils {private stat
package com.cn.utils;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
//c3p0 会自动读取c3p0-config.xml文件(默认放在class目录下,会被自动读取)
public class C3P0Utils {
private static DataSource source;
static{
source = new ComboPooledDataSource();//可以在c3p0的配置文件配置,选择要使用的数据库,不指定就使用默认配置项
//读取c3p0-config.xml文件中的信息,默认读取default-config配置的信息
}
public static DataSource getSource(){
return source;
}
//不读取c3p0-config.xml,手动配置的方式
/*private static ComboPooledDataSource com =null;
static{
try {
com.setDriverClass("com.mysql.jdbc.Driver");
com.setJdbcUrl("jdbc:mysql://localhost:3306/web");
com.setUser("root");
com.setPassword("123456");
com.setMaxPoolSize(20);
com.setMinPoolSize(10);
com.setInitialPoolSize(5);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}*/
}
