我怀疑是连接池没有把连接回收导致的,tomcat不支持大的连接数

解决方案 »

  1.   

    这是连接池的  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();
        }
      

  2.   

    是连接池的问题...你在写jsp程序时,用完一个数据库联结,就要释放它....这个是一定的...
      

  3.   

    to yingyeqi(风中男孩)
    我在final里释放连接了,即使出错的话,也会调用final的
      

  4.   

    在Connection上调用close方法会关闭Statement和ResultSet吗?级联的关闭这听起来好像很有道理,而且在很多地方这样做也是正确的,通常这样写
    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) {
            ///错误处理
        }
    }很麻烦是不是?但为了写出健壮的程序,这些处理是必须的。
      

  5.   

    同意zww80216(雨后晴天)的说法
    btw:把Connection关闭了,却继续使用ResultSet,认为这样是可以的在没有关闭ResultSet,Connection放回连接池时是对的吧to all
    问题解决了,因为同伴自己写了一个DAO,在那个DAO里没有释放资源,sign
      

  6.   

    1.连接池中不要动不动就release,因为这样就失去了连接池的意义.
    2. conn 为不为空,用完后,都要还回去.
    3。用了不要 con.close();因为这样就失去了连接池的意义.