我用servlet验证用户登陆...............................
String connuser = "root";
String connpassword = "password";
String driver = "com.mysql.jdbc.Driver";
String url = "mysql:jdbc://localhost:3306/admin";
Connection conn = null;
String sql = "select * from login where adminname=?,adminpassword=?";


String username = request.getParameter("username");
String password = request.getParameter("password");

try {
Class.forName(driver);
conn = DriverManager.getConnection(url, connuser, connpassword);
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs = ps.executeQuery(sql);

if(rs==null||rs.next()==null){    //The operator == is undefined for the 
return;                                          //  argument type(s) boolean null
}                                                        //这应该没有问题吧,返回都是boolean......
                                                                                 //不知道为什么呀??


} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}......................................

解决方案 »

  1.   


    if(rs==null||rs.next()==null){    //The operator == is undefined for the
    return;                                          //  argument type(s) boolean null
    } //改成这样
    if(rs.next()){
      return true;
    }else{
      return false; 
    }
      

  2.   


    //或者这样
    if (rs != null && rs.next()) {
      return true;
    }else{
      return false; 
    }
      

  3.   

    rs.next()返回的是布尔值 true or false