1.
类路径下c3p0-config.xml
<c3p0-config>
<named-config name="">
<property name=""></property>
</named-config>
</c3p0-config>
类路径下c3p0.properties
key=value
2.
ComboPooledDataSource dataSource = new ComboPooledDataSource("1的named-config的name属性值对应");
ComboPooledDataSource dataSource = new ComboPooledDataSource();
Properties props = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream stream = loader.getResourceAsStream("c3p0.properties");
props.load(stream);
dataSource.setDriverClass(props.getProperty(key));
//dataSource.setxxx设置属性和在配置文件里设置一样,dataSource.getxxx获得属性
dataSource.toString(true)//可以输出看到配置的信息
dataSource.close();//关闭
c3p0
最新推荐文章于 2024-06-26 21:59:00 发布