如果有为什么没有isClosed()方法?

解决方案 »

  1.   

    void close()
    这个方法难道还不满足楼主需要? 
      

  2.   

    需要关闭 这样才能释放该Statement对象占用的资源....
    if(rs   !=   null){   
          try{
             rs.close();
             rs = null;
          }catch(Exception   e){}   
      }   
      if(st   !=   null){   
          try{
              st.close();
              st = null;
          }catch(Exception   e){}   
      }   
      if(con   !=   null){   
          try{
             con.close();
             con = null;
           }catch(Exception   e){}   
      }
    ....
      

  3.   

    同意楼上的,需要关闭释放资源,其实你只要关闭Connection连接,那么Statement也就会随之关闭
      

  4.   

    ....
    if(rs   !=   null){   
          try{
             rs.close();
             rs = null;
          }catch(Exception   e){}   
      }   
      if(st   !=   null){   
          try{
              st.close();
              st = null;
          }catch(Exception   e){}   
      }   
      if(con   !=   null){   
          try{
             con.close();
             con = null;
           }catch(Exception   e){}   
      }
    ....
    就是这样,由里往外关闭啊
      

  5.   


    statment 还是要关闭的,否则可能引起内存泄露
      

  6.   

    楼主最好将 Connection、Statement 和 ResultSet 放在同一个对象中创建和关闭,否则这个逻辑就复杂了。
      

  7.   

    isClosed()方法需要特殊的支持,所以就算有也可能不能用,
    要验证连接是否关闭需要尝试和数据库之间交互消息,并且有过期时间的,
    还是用别的途径吧
      

  8.   

    关闭连接Connection.close()。
    isClosed();是判断是否关闭连接的吧
      

  9.   

    我一般每次连接的时候只关闭Connection 就可以了!
    用了这么长时间也没发生什么问题,
    不过为了程序的健壮性还是都关闭的比较好。
      

  10.   

    问6楼:
    楼主最好将 Connection、Statement 和 ResultSet 放在同一个对象中创建和关闭
    如何做到??
      

  11.   

    但问题是我关多了,自己也不知道,是否已经关了
    如果在关了的基础上再close,那会出错的。
      

  12.   

    需要关闭
    statement.close();在
    connection.close();之前
    具体看程序要求
      

  13.   

    Statement  Connection 是需要关闭的!
      

  14.   


    Statement st = null;
    try{
       //LZ想做什么就做什么吧。JCBC一般是
       st = con.createStatement;
    }catch(Exception ex){
      ex.printStackTrace();
    }finally{
       if(st!=null){
       st.close();//难道此方法不能满足LZ您的需要吗?
    }
    }
      

  15.   

    关闭时最好是ResultSet、Statement 、Connection这个顺序
      

  16.   

    一般关闭的时候先判断
    if(rs!=null){
        rs.close();
        rs=null;//一般是加这个的。
    }
    你再关闭的时候,rs==null,不会再去关闭了。
      

  17.   

    rs.close();
    你再关一次
    rs.close();//不会有任何操作。rs也不为空,怎么出错
      

  18.   


    rs=null;//一般是加这个的。 
    此处语句还有含义吗?