http://haoran-10.iteye.com/blog/1753332java
配置文件放置:mysql
You can use the XML config file for all c3p0 configuration, including configuration of defaults, named configurations, per-user overrides, and configuration extensions.sql
By default, c3p0 will look for an XML configuration file in its classloader's resource path under the name "/c3p0-config.xml". That means the XML file should be placed in a directly or jar file directly named in your applications CLASSPATH, in WEB-INF/classes, or some similar location.oracle
If you prefer not to bundle your configuration with your code, you can specify an ordinary filesystem location for c3p0's configuration file via the system property com.mchange.v2.c3p0.cfg.xml. (You can also use this property to specify an alternative location in the ClassLoader resource path, e.g. META-INF. See Locating Configuration Information.)app
Here is an example c3p0-config.xml file:ide
<c3p0-config> <default-config> <property name="user">xxx</property> <property name="password">xxxxx</property> <property name="driverClass">oracle.jdbc.OracleDriver</property> <property name="jdbcUrl">jdbc:oracle:thin:@127.0.0.1:1533:xxdb</property> <property name="initialPoolSize">10</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">100</property> <property name="minPoolSize">10</property> </default-config> <named-config name="mySource"> <property name="user">root</property> <property name="password">java</property> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property> <property name="initialPoolSize">10</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">100</property> <property name="minPoolSize">10</property> </named-config> </c3p0-config>
DataSource ds 的使用方法以下,默认根据启动配置里面可使用的链接池数目,超过配置的poolsize后,ds.getConnection()方法将等待,有释放的connection。this
static DataSource ds=null; public static Connection getOracleConnection() { Connection connection=null; if(ds==null){ ds=new ComboPooledDataSource(); } try { connection=ds.getConnection(); } catch (SQLException e) { e.printStackTrace(); } return connection; }
参考http://www.mchange.com/projects/c3p0/#basic_pool_configurationspa