使用C3P0数据源

C3P0数据源
一、拷贝jar包
 在c3p0发行包的lib目录中
  c3p0-0.9.1.2.jar
  c3p0-0.9.1.2-jdk1.3.jar
  c3p0-oracle-thin-extras-0.9.1.2.jar(oracle)
二、在类路径下建立一个名为c3p0-config.xml的配置文件
 <c3p0-config>
 <named-config name="day14">
  <property name="driverClass">com.mysql.jdbc.Driver</property>
  <property name="jdbcUrl">jdbc:mysql:///day14</property>
  <property name="user">root</property>
  <property name="password">sorry</property>
  <property name="acquireIncrement">10</property>
  <property name="initialPoolSize">30</property>
  <property name="minPoolSize">5</property>
  <property name="maxPoolSize">40</property>
  <property name="maxStatements">1000</property>
  <property name="maxStatementsPerConnection">100</property>
 </named-config>
</c3p0-config>
三、创建一个工具类,根据配置文件获取数据源
 private static ComboPooledDataSource ds = new ComboPooledDataSource ("day14");
 
 public static Connection getConn() throws SQLException{
  return ds.getConnection();
 }mysql

相关文章
相关标签/搜索