Cannot get a connection, pool exhausted解决办法

来源:互联网 发布:电脑直播变声软件 编辑:程序博客网 时间:2024/04/30 01:54
 Cannot get a connection, pool exhausted解决办法     CSDN Blog推出文章指数概念,文章指数是对Blog文章综合评分后推算出的,综合评分项分别是该文章的点击量,回复次数,被网摘收录数量,文章长度和文章类型;满分100,每月更新一次。
昨天看了下数据库连接池,有很多开源的连接池,为了方便就使用了tomcat中带的连接池,
开始找了几篇文章,都没有弄成功,tomcat图形管理界面创建连接池的也不好用,
后来在网上找了一篇tomcat5.5的配置文章,总算是解决了,
按照下面的例子试了下,刷新几次后就出现了
Cannot get a connection, pool exhausted
后来搜了一下,是连接池被耗尽,
没有关闭con,
解决办法有3个:
1重启tomcat服务器
2吧maxactive值调大
3在finally中关闭conn

Context initCtx=new InitialContext();
DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/mysql");
c.getConnection();
out.println("从数据库查询数据:<br>");
Statement stmt=conn.createStatement();
ResultSet rs =stmt.executeQuery("select * from userinfo");
while(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
rs.close();
stmt.close();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(conn!=null)
conn.close();