怎么tomcat运行一段时间后,会抛出The server is busy异常 我怀疑是连接池没有把连接回收导致的,tomcat不支持大的连接数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是连接池的 releaseConnection方法 public synchronized void releaseConnection(Connection connection) throws WrongPoolException, SQLException { if (usedConnections.containsKey(connection)) { usedConnections.remove(connection); if (!connection.isClosed()) { if (shuttingDown) {////.println("[CP] releasing connection during shutdown " + connection); try { connection.close(); } catch (SQLException sex) { } } else {////.println("[CP] releasing connection " + connection); freeConnections.add(connection); } } else {////.println("[CP] releasing closed connection " + connection); // do nothing, let the connection object be GCed } } else { throw new WrongPoolException(); } this.notifyAll(); } 是连接池的问题...你在写jsp程序时,用完一个数据库联结,就要释放它....这个是一定的... to yingyeqi(风中男孩)我在final里释放连接了,即使出错的话,也会调用final的 在Connection上调用close方法会关闭Statement和ResultSet吗?级联的关闭这听起来好像很有道理,而且在很多地方这样做也是正确的,通常这样写Connection con = getConnection();//getConnection is your methodPreparedStatement ps = con.prepareStatement(sql);ResultSet rs = ps.executeQuery();……///rs.close();///ps.close();con.close(); // NO!这样做的问题在于Connection是个接口,它的close实现可能是多种多样的。在普通情况下,你用DriverManager.getConnection()得到一个Connection实例,调用它的close方法会关闭Statement和ResultSet。但是在很多时候,你需要使用数据库连接池,在连接池中的得到的Connection上调用close方法的时候,Connection可能并没有被释放,而是回到了连接池中。它以后可能被其它代码取出来用。如果没有释放Statement和ResultSet,那么在Connection上没有关闭的Statement和ResultSet可能会越来越多,那么……相反,我看到过这样的说法,有人把Connection关闭了,却继续使用ResultSet,认为这样是可以的,引发了激烈的讨论,到底是怎么回事就不用我多说了吧。所以我们必须很小心的释放数据库资源,下面的代码片断展示了这个过程Connection con = null;PreparedStatement ps = null;ResultSet rs = null;try { con = getConnection();//getConnection is your method ps = con.prepareStatement(sql); rs = ps.executeQuery(); ///...........}catch (SQLException ex) { ///错误处理}finally{ try { if(rs!=null) rs.close(); if(ps!=null) ps.close(); if(con!=null) con.close(); } catch (SQLException ex) { ///错误处理 }}很麻烦是不是?但为了写出健壮的程序,这些处理是必须的。 同意zww80216(雨后晴天)的说法btw:把Connection关闭了,却继续使用ResultSet,认为这样是可以的在没有关闭ResultSet,Connection放回连接池时是对的吧to all问题解决了,因为同伴自己写了一个DAO,在那个DAO里没有释放资源,sign 1.连接池中不要动不动就release,因为这样就失去了连接池的意义.2. conn 为不为空,用完后,都要还回去.3。用了不要 con.close();因为这样就失去了连接池的意义. portal 开发 求crystal report 下载。。。。。 在线等~~form表单提交 jsp查询模块设计,高手请进~~ getParameter中文乱码问题 我的网站发布到服务器,昨天还行,正常运行, 今天就不行了,求高手解决额 ,万谢! 三个页面小问题 java的简单问题!解决立即给分! 关于vector的两个问题以及关于使用java.lang.Math里的log的一个问题,请指教,急!多谢! 数据库查询问题 帮忙看一下写入数据库的代码!! 求jsp电子书
public synchronized void releaseConnection(Connection connection)
throws WrongPoolException, SQLException {
if (usedConnections.containsKey(connection)) {
usedConnections.remove(connection);
if (!connection.isClosed()) {
if (shuttingDown) {
////.println("[CP] releasing connection during shutdown " + connection);
try {
connection.close();
} catch (SQLException sex) {
}
} else {
////.println("[CP] releasing connection " + connection);
freeConnections.add(connection);
}
} else {
////.println("[CP] releasing closed connection " + connection);
// do nothing, let the connection object be GCed
}
} else {
throw new WrongPoolException();
}
this.notifyAll();
}
我在final里释放连接了,即使出错的话,也会调用final的
Connection con = getConnection();//getConnection is your method
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
……
///rs.close();
///ps.close();
con.close(); // NO!
这样做的问题在于Connection是个接口,它的close实现可能是多种多样的。在普通情况下,你用DriverManager.getConnection()得到一个Connection实例,调用它的close方法会关闭Statement和ResultSet。但是在很多时候,你需要使用数据库连接池,在连接池中的得到的Connection上调用close方法的时候,Connection可能并没有被释放,而是回到了连接池中。它以后可能被其它代码取出来用。如果没有释放Statement和ResultSet,那么在Connection上没有关闭的Statement和ResultSet可能会越来越多,那么……
相反,我看到过这样的说法,有人把Connection关闭了,却继续使用ResultSet,认为这样是可以的,引发了激烈的讨论,到底是怎么回事就不用我多说了吧。所以我们必须很小心的释放数据库资源,下面的代码片断展示了这个过程Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;try {
con = getConnection();//getConnection is your method
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
///...........
}
catch (SQLException ex) {
///错误处理
}
finally{
try {
if(rs!=null)
rs.close();
if(ps!=null)
ps.close();
if(con!=null)
con.close();
}
catch (SQLException ex) {
///错误处理
}
}很麻烦是不是?但为了写出健壮的程序,这些处理是必须的。
btw:把Connection关闭了,却继续使用ResultSet,认为这样是可以的在没有关闭ResultSet,Connection放回连接池时是对的吧to all
问题解决了,因为同伴自己写了一个DAO,在那个DAO里没有释放资源,sign
2. conn 为不为空,用完后,都要还回去.
3。用了不要 con.close();因为这样就失去了连接池的意义.