1.参看CP30文档quickStart

如下具体创建步骤

 public DataSource getDs() throws Exception {
         //创建连接池对象
         ComboPooledDataSource cpds = new ComboPooledDataSource();
         cpds.setDriverClass("com.mysql.jdbc.Driver");
         cpds.setJdbcUrl("jdbc:mysql://localhost:3306/jdbcdemo");
         cpds.setUser("root");
         cpds.setPassword("4230");
         return cpds;
     }

2.调用上述方法创造的DataSource连接池对象进行查询操作

 @Test
     public void testQuery() throws Exception {
         Connection connec = getDs().getConnection();
         String sql = "SELECT * FROM student";
         PreparedStatement ps = connec.prepareStatement(sql);
         ResultSet rSet = ps.executeQuery();
         while(rSet.next()){
             System.out.println(rSet.getLong(1) + "-" + rSet.getString(2) + "-" + rSet.getInt(3));
         }
         DBCPUtil.close(rSet, ps, connec);
     }
05-08 14:55