数据库连接池——C3P0连接池

1 C3P0简介

  C3P0也是开源免费的连接池!C3P0被很多人看好!

 

2 C3P0的使用

  C3P0中池类是:ComboPooledDataSource。

    public void fun1() throws PropertyVetoException, SQLException {

       ComboPooledDataSource ds = new ComboPooledDataSource();

       ds.setJdbcUrl("jdbc:mysql://localhost:3306/mydb1");

       ds.setUser("root");

       ds.setPassword("123");

       ds.setDriverClass("com.mysql.jdbc.Driver");

[崔1]       

       ds.setAcquireIncrement(5)[崔2] ;

       ds.setInitialPoolSize(20)[崔3] ;

       ds.setMinPoolSize(2)[崔4] ;

       ds.setMaxPoolSize(50)[崔5] ;

      

       Connection con = ds.getConnection();

       System.out.println(con);

       con.close();

    }

 

配置文件要求:

  1. 文件名称:必须叫c3p0-config.xml
  2. 文件位置:必须在src下

 [崔1]基本配置

 [崔2]每次的增量为5

 [崔3]初始化连接数

 [崔4]最少连接数

 [崔5]最多连接数

猜你喜欢

转载自blog.csdn.net/weixin_42472048/article/details/82930929