@Test
    public void fun1() {
        /*
         * 1创建链接对象
         */
        BasicDataSource bds = new BasicDataSource();
        bds.setDriverClassName("com.mysql.jdbc.Driver");
        bds.setUrl("jdbc:mysql://localhost:3306/blog");
        bds.setUsername("root");
        bds.setPassword("root");
        
        bds.setMaxActive(20);
        bds.setMinIdle(3);
        bds.setMaxWait(1000);
        
        
        try {
            Connection con = bds.getConnection();
            System.out.println(con.getClass().getName());
        } catch (SQLException e) {            
            e.printStackTrace();
        }
        /*
         * 链接池内部使用四大参数创建了链接对象,即mysql驱动提供的connection
         * 连接池使用MySQL的连接对角象进行装饰,只对close方法进行了增强
         * 装饰之后的,Connection的close()方法,用来把当前链接归还给池
         */
    }

连接池的创建使用 二

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2021-10-09
  • 2021-11-24
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2021-08-17
  • 2022-02-26
  • 2021-07-10
  • 2021-10-28
  • 2021-12-31
  • 2021-07-30
相关资源
相似解决方案