@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()方法,用来把当前链接归还给池
*/
}
连接池的创建使用 二
猜你喜欢
转载自blog.csdn.net/weixin_41957098/article/details/88765087
今日推荐
周排行