在pom.xml文件中导入jar包
<dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5.2</version> </dependency>

在src目录下创建c3p0-config.xml文件

<c3p0-config><named-config name="mysqlapp"><!-- 提供获取连接的4个基本信息 --><property name="driverClass">com.mysql.cj.jdbc.Driver</property><property name="jdbcUrl">jdbc:mysql://192.168.153.143:3306/jdbcstudb</property><property name="user">root</property><property name="password">941006</property><!-- 进行数据库连接池管理的基本信息 --><!-- 当数据库连接池中的连接数不够时,c3p0一次性向数据库服务器申请的连接数 --><property name="acquireIncrement">5</property><!-- c3p0数据库连接池中初始化时的连接数 --><property name="initialPoolSize">10</property><!-- c3p0数据库连接池维护的最少连接数 --><property name="minPoolSize">10</property><!-- c3p0数据库连接池维护的最多的连接数 --><property name="maxPoolSize">600</property><!-- c3p0数据库连接池最多维护的Statement的个数 --><property name="maxStatements">50</property><!-- 每个连接中可以最多使用的Statement的个数 --><property name="maxStatementsPerConnection">2</property></named-config>
</c3p0-config>
测试
public class C3p0Util {private static DataSource dataSource = null;static {dataSource = new ComboPooledDataSource("mysqlapp");}public static Connection getConnection() {try {return dataSource.getConnection();} catch (SQLException e) {e.printStackTrace();}return null;}public static void main(String[] args) {Connection connection = getConnection();System.out.println(connection);}
输出下面语句表示成功!其中红色的不是报错,而是日志


















