java配置连接C3P0数据库

java配置连接C3P0数据库

导入jar包

在这里插入图片描述

代码

package com.jp;
import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.SQLException;

/**
 * @program: Test01
 * @description: c3p0数据库连接池使用
 * @author: CoderPengJiang
 * @create: 2019-12-19 22:09
 **/
public class C3P0Test {
    public static void main(String[] args) throws PropertyVetoException, SQLException {
        //核心类
        ComboPooledDataSource dataSource=new ComboPooledDataSource();
        //基本的四项设置
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql://192.168.127.128:3306/blog");
        dataSource.setUser("root");
        dataSource.setPassword("201314");
        //其他设置
        //初始化连接数为10
        dataSource.setInitialPoolSize(10);
        //设置最大的连接数为20
        dataSource.setMaxPoolSize(20);
        //设置最小的连接数
        dataSource.setMinPoolSize(3);
        //设置每次创建的连接数
        dataSource.setAcquireIncrement(3);
        System.out.println(dataSource.getConnection());
    }
}

输出

在这里插入图片描述

发布了9 篇原创文章 · 获赞 9 · 访问量 831

猜你喜欢

转载自blog.csdn.net/qq_36908783/article/details/103624518
今日推荐