try{

String name= new String(request.getParameter("uid"));
String password= new String(request.getParameter("upwd"));
    
    DataBase db= new DataBase();  //DataBase 是个数据库的类     
    String sql = "select * from XT_YHXX where YHMC='" +  name + "' and YHMM='" + password + "' and YXBZ='Y'";
    
        
    ResultSet rs=db.select(sql);     
    
       
       }
   
   catch(Exception e)
   {
   
        String str = "登陆信息出错了!";
        
     
    response.sendRedirect( "error.jsp?mess='" + str  +"'");
   
   } 
   finally
   {
       boolean t = db.close();
      /*
       if(db.close() == true)
       {
            if(rs!=null)
        {        
           rs.close();
             }
       }
   */   
   
   }    DataBase类中的 close  方法 
 public boolean close(){
        try{
            if(rs!=null){
                rs.close();
            }
            if(stmt!=null){
                stmt.close();
            }
            if(conn!=null){
                conn.close();
            }
            return true;
        }catch(Exception e){
            System.err.println("关闭失败!");
            return false;
        }
    }这个语句:boolean t = db.close();
 放到try 最后可以执行,为什么放在finally执行不了?提示错误: 
cannot resolve symbol
symbol  : variable db 
location: class org.apache.jsp.login_jsp
       boolean t = db.close();

解决方案 »

  1.   

    DataBase db= new DataBase();
    放try前面我习惯,try前加一个标示变量=false,catch中=true, finally后面 if(变量){response.sendRedirect()}
      

  2.   

    DataBase db= null;try{String name= new String(request.getParameter("uid"));
    String password= new String(request.getParameter("upwd"));
      
    db= new DataBase(); //DataBase 是个数据库的类  
    finally
      {
    if(db != null) {
     db.close();
    }
      /*  
      

  3.   

    db放到TRY里面new的是局部变量