What I\'m trying to do is:
Accept username(uname) and password(passw) as an input from the user.
Using ResultSet
, retrieve the
@Eran mentioned the error by which a wrong id would yield an empty result set on which fields were gotten.
I still have small remarks:
Thus:
boolean loggedIn = false;
try (PreparedStatement stmt =
conn.prepareStatement("SELECT 1 FROM admin WHERE id = ? AND pass = PASSWORD(?)")) {
stmt.setString(1, uname);
stmt.setString(2, passw);
try (ResultSet rs = stmt.executeQuery()) {
loggedIn = rs.next();
} // Closes rs.
} // Closes stmt.
You are supposed to use the result of rs.next()
:
if (rs.next()) {
n=rs.getString("id");
m=rs.getString("pass");
}
If rs.next()
returns false, this means the query returned no rows.