java - Unable to get required JDBC Exception -


i have created login form using java servlets , jsp's. login information such username , password saved in database. question when user enters information java class fails find in database dont exception. how create exception if login data isnt available in db?

public boolean loginvalidator(string e, string p) throws sqlexception {      string username = e;     string password = p;     boolean validate = false;     try{     preparedstatement ps = connection.preparestatement("select * user email = ? , password = ?");     ps.setstring(1, username);     ps.setstring(2, password);      resultset rst = ps.executequery();      while (rst.next()) {         validate = (rst.getstring("email").equals(username)) && ((rst.getstring("password").equals(password)));     }}     catch(sqlexception ex){         system.out.println(ex.getmessage());         validate = false;     }   return validate; } 

this method in java class validates , send boolean type servlet , later servlet decides direct or restrict access application subject boolean type returned.

ps: new learner of javaweb.

and learner of sql, right? because there no exception, if there no such line in db table. query returns empty resultset. have check, whether result set empty or not (and alternatively check email , password - imho superfluous).

public boolean loginvalidator(string username, string password) {     try{         preparedstatement ps = connection.preparestatement("select * user email = ? , password = ?");         ps.setstring(1, username);         ps.setstring(2, password);         resultset rst = ps.executequery();         return rst.next(); // whether db contains such record     } catch(sqlexception ex){         ex.printstacktrace(); // tip: use logging     }     return false; } 

btw. recommend not store plaintext passwords in db.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -