rs.close();
stmt.close();
con.close;
肯定没错。

解决方案 »

  1.   

    一定要楼上说的顺序关闭。光关conn是不行的。否则记录集越大次数越多数据库的资源就撑爆了。
      

  2.   

    一般都推荐这样写:
    if(rs != null){
      try{rs.close()}catch(Exception e){}
    }
    if(state != null){
      try{state.close()}catch(Exception e){}
    }
    if(conn != null){
      try{conn.close()}catch(Exception e){}
    }
      

  3.   

    con,stmt,rsstmt=con.createStatement();rs=stmt.executeQuery(sql);如果关闭连接,那么记录集肯定还是存在的。至于statement,个人认为它也是存在的,但是没有连接,所以无法使用和获得!
      

  4.   

    JDBC API里的解释:
    con.close();
    关闭与数据库的连接,并释放Connection对象几该连接占用的相关资源。
    rs.close();
    释放ResultSet对象所占用的资源。
    stmt.close();
    释放该Statement对象占用的资源。从以上的解释看来还是要关闭才不会浪费资源。
      

  5.   

    在非自动事务模式下,即AutoCommit=false时,stmt一定要关闭,否则同一个连接只能用一次,多次使用时会报 Cannot Start a Cloned Connection While in Manual Transaction Mode 错误。养成良好的编程习惯对于系统的稳定和健壮性是很重要的。
      

  6.   

    to  ningIII(小宁):如果关闭连接,那么记录集肯定还是存在的。-------------严重错误
    连接关闭掉,结果集则不存在,resultset对象是要保持连接的状态下才有用的.
      

  7.   

    to  ningIII(小宁):如果关闭连接,那么记录集肯定还是存在的。-------------严重错误
    连接关闭掉,结果集则不存在,resultset对象是要保持连接的状态下才有用的.
      

  8.   

    一般来说把conn关掉之后,和它相关联的stmt、rs会自动关闭。不过为了程序的完整性你不妨可以这样做
    if(rs != null){
      try{rs.close()}catch(Exception e){}
    }
    if(state != null){
      try{state.close()}catch(Exception e){}
    }
    if(conn != null){
      try{conn.close()}catch(Exception e){}
    }
      

  9.   

    connection可以被重复使用的。只是每次只能建立一个statement/preparedstatement,所以可以把connection用池缓存起来,而statement/preparedstatement关掉.