关键是要找出来。
包括ResultSet和Statement.

解决方案 »

  1.   

    所有的数据库连接,什么意思?当前JVM内所有线程连接数据库的连接?
      

  2.   

    当前可以,举个例子
    一般情况把数据库推辞封装成成一个类 
    public class DataBase { private static Connection conn;

    private static PreparedStatement pstmt; private static Statement stmt;

    private static ResultSet rs; public void close(){
    try {
    closeRs();
    closePstmt();
    closeConn();
    } catch (SQLException e){
    System.err.println("关闭资源出错!!!---" + e.getMessage());
    }
    }
            public void closeRs() throws SQLException{
    if(rs != null) {
    rs.close();
    rs = null;
    }
    }

    public void closePstmt() throws SQLException{
    if(pstmt != null) {
    pstmt.close();
    pstmt = null;
    }
    }

    public void closeConn() throws SQLException{
    if(conn != null) {
    conn.close();
    conn = null;
    }
    }
    }
      

  3.   

    另外关闭的语句要写到finally里面
    这样不管过程出不出错 连接都会关闭掉
      

  4.   

    4楼:
    问题就在这里。
    我使用时,ResultSet通常,有不同的变量名。
    但在你的代码里已经定死了它的名字。
    这样,关闭不停于白关吗?
      

  5.   


       public void close(Connection conn,Statement st,ResultSet rs) throws SQLException
      {
          try {
            if(conn!=null)
            conn.close();
            if(st!=null)
              st.close();
            if(rs!=null)
              rs.close();
          }
          catch (SQLException e) {
            e.printStackTrace();
            throw e;
          }
       
      }这样不就行了
      

  6.   

    10楼的方法是简单,不知道是否可行。
    我觉得应该这样改下。
    if(conn!=null && !conn.iscolsed())
       conn.close();
    不知道大家是否赞同。。
      

  7.   

    数据库连接被关掉之后是null吗?
      

  8.   

    楼主要把代码组织好啊,不要把 ResultSet 乱丢。
      

  9.   

    如果你用数据库连接不马上关闭,效率不会很高,程序设计绝对有问题如果你有个业务,需要运行10条SQL语句,你怎么做?用1个数据库连接还是10个?