c3p0连接池

1,导入c3p0的jar包

2,src下创建配置文件(c3p0-config.xml)

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
    <default-config>                                                  <!-- 默认的链接 创建C3P0是不输入参数,或输入错误时使用默认 -->
        <property name="driverClass">com.mysql.jdbc.Driver</property> <!-- 数据驱动 -->
        <property name="jdbcUrl">jdbc:mysql:///dang?generateSimpleParameterMetadata=true</property> <!-- 数据库的URL 后面的参数是允许获得参数类型名称 -->
        <property name="user">root</property>                          <!-- 数据库用户名 -->
        <property name="password">123</property>                      <!-- 数据库密码 -->
        <property name="initialPoolSize">5</property>                  <!-- 初始化时创建的的链接对象数 -->
        <property name="acquireIncrement">3</property>                  <!-- 连接对象的增量(连接池数量不够用时创建的数量) -->
        <property name="minPoolSize">2</property>                      <!-- 最小链接对象 -->
        <property name="maxPoolSize">10</property>                      <!-- 最大链接对象 -->
    </default-config>

    <named-config name="oracle-config">                                  <!-- oracle的配置 -->
        <property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb1</property>
        <property name="driverClass">com.mysql.jdbc.Driver</property>
        <property name="user">root</property>
        <property name="password">099418</property>
        <property name="acquireIncrement">3</property>
        <property name="initialPoolSize">10</property>
        <property name="minPoolSize">2</property>
        <property name="maxPoolSize">10</property>
    </named-config>
</c3p0-config>
View Code

3,创建连接池对象:(private static final修饰)

 private static final ComboPooledDataSource DATASOURCE = new ComboPooledDataSource(); 

原文地址:https://www.cnblogs.com/laodang/p/9504542.html