Statement stmt = conn.createStatement(); 
1.你的stmt是在try块里面定义的,到了finally就已经超过stmt变量的作用域范围了,当然无法通过编译,改成:
Statement stmt = null;
try{
   stmt = conn.createStatement(); 
   ...
}finally{...}2.这些close方法都可能抛出SQLException的,必须要再try一次
3.conn, rs, stmt可能会是null,要判断一下:
finally{
   try{
      if(null != rs) rs.close();
      if(null != stmt) stmt.close();
      if(null != conn) conn.close();
   }catch(SQLException se){}
}

解决方案 »

  1.   

    但是应用时出现错误,是不是和return rs; 有关系?我把关闭数据库的三条语句,放进了try中!
      

  2.   

    我把关闭数据库的三条语句,放进了try中。但是应用时出现错误,是不是和return rs; 有关系?
      

  3.   

    我晕,你rs都close还return回去?如果要return rs回去,三个都不能关
      

  4.   

    return rs回去,之后如何关闭数据库呢?
      

  5.   

    try{
      return rs;
    }catch(...){
      return null;
    }finally{
      ...
    }
      

  6.   

    返回rs是一个非常烂的设计,劝你还是改改,bean里面把数据读出来放在list返回去然后关闭所有资源
      

  7.   

    我在CLASS文件中增加了下列代码:public void Close() 

    try 

    if(rs !=null) 
    rs.close(); 
    if(conn !=null) 
    conn.close(); 

     catch(SQLException ex) {    System.err.println("db.executeUpdate: " + ex.getMessage()); 
      } 
    } 然后在JSP中调用,db.Close();  但是出现错误信息:javax.servlet.ServletException: Logon failed: Connection reset
    如何解决?还是我的代码写的有问题?