c3p0怎么加载配置文件?不用hibernate和spring,怎么从配文件设置连接池?j2se程序.
不是web程序 大家注意啦
就是一个普通的可以应用的main程序
------解决方案--------------------
配置文件格式你可以自己定义,并解析不难。c3p0 api可见下面例子,你要下载c3p0的jar到你工程中;解析好格式后把属性设置给c3p0的ComboPooledDatasource的对象就OK了
public static void main(String[] args) throws Exception {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("oracle.jdbc.OracleDriver");
cpds.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:orcl");
cpds.setUser("mmc");
cpds.setPassword("mmc");
cpds.setMinPoolSize(5);
cpds.setMaxStatements(50);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(20);
Connection con = cpds.getConnection();
try {
Statement stmt = con.createStatement();
con.setAutoCommit(true);
stmt.executeUpdate("CREATE TABLE tempTab (id VARCHAR(32) ,name VARCHAR(32),age NUMBER,score NUMBER)");
stmt.executeUpdate("delete from tempTab");
stmt.executeUpdate("INSERT INTO tempTab VALUES ('075','joyce',22,90)");
stmt.executeUpdate("INSERT INTO tempTab VALUES ('071','LILY',23,80)");
stmt.executeUpdate("INSERT INTO tempTab VALUES ('072','MOMO',22,88)");
String sql = "SELECT C.id, C.name from tempTab c";