首页 新闻 会员 周边

关于dbcp池有两处问题,红字那里。

0
悬赏园豆:5 [待解决问题]

import java.sql.SQLException;

import org.apache.commons.dbcp2.BasicDataSource;

public class TestDbcp {

public static void main(String[] args) {
// TODO Auto-generated method stub
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/demo");
dataSource.setUsername("root");
dataSource.setPassword("0524");
dataSource.setMaxActive(10);
dataSource.setInitialSize(2);
Connection conn=null;
for(int i=0;i<15;i++){
try{
conn=dataSource.getConnection();
System.out.println("connection"+i+":"+conn.hashCode());
}catch(SQLException e){
e.printStackTrace();
}
}
}

}

KirkZheng的主页 KirkZheng | 初学一级 | 园豆:116
提问于:2017-01-01 01:13
< >
分享
所有回答(2)
0

MaxActive,连接池的最大数据库连接数。设为0表示无限制

http://commons.apache.org/proper/commons-dbcp/configuration.html

2012 | 园豆:21230 (高人七级) | 2017-01-02 09:35
0

你想知道什么呀?

大水煮鱼 | 园豆:366 (菜鸟二级) | 2017-01-03 16:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册