在statement不用的时候调用stmt.close
什么时候都要调用,不要不调用,这是好习惯

解决方案 »

  1.   

    摘录一些别人的说法:
    If you close the connection, Statements created from that connection will be closed.
    If you close the statement, Resultets open from that statement will be close.Always close ResultSet, Statements and Connections in that order. If you don't close the statements or resultsets they might hang around until the get garbage collected, and even after that they might take valuable resources on the database server. I always uses a finally clause with the close logic as below. If you don't have separete try clauses for each close operation a failed resultSet might leave a connection open, and we don't want that.
      

  2.   

    但如果我没有关闭stmt,那么我下次还能再使用吗?好像ResultSet每次用完后都要关闭啊!
      

  3.   

    我觉得还是用完记录集后就Close()掉,这样是个好习惯!
      

  4.   

    在它的作用域内,Statement会一直存在
      

  5.   

    你不关statement,在关Connection时会帮你关了statement.
    用一个statement是可以多次查询的,不是每ResultSet用完关闭.
      

  6.   

    应该这样规范:
    try {
      ......
    } catch( Exception e ) {
    } finally {
      res.close();
      stmt.close();
      con.close();
    }
      

  7.   

    to adub:
    你这样写能成功吗???我为什么都不成功。。我是这样写的
    try {
      ......
    } catch( Exception e ) {
    } finally {
      try{
        res.close();
        stmt.close();
        con.close();
      }catch(Exception e){
      }
    }
      

  8.   

    在使用连接池的时候一定要关, 我做了一个能自动监控的package.
    需要的请给我mail: [email protected]
      

  9.   

    to adub:
    你这样写能成功吗???我为什么都不成功。。我是这样写的
    try {
      ......
    } catch( Exception e ) {
    } finally {
      try{
        res.close();
        stmt.close();
      }catch(Exception e){
      }finally {
        try {
        con.close();
       }catch(...) {}
      }
    }Connection 最重要,如果前面的close抛出异常,你的connection就没关掉