Login Validation with JDBC
843859Aug 11 2008 — edited Aug 12 2008When I validate the user name and password from student table, I get null pointer exception if no match found. How to handle this situation
1. Is it a best way to check both user name and password in the query itself? or
2. Can I check the password alone using IF construct in While loop?
ps = con.prepareStatement("select * from student where stdid like ? and password like ?");
ps.setString(1,a);
ps.setString(2,b);
rs= ps.executeQuery();
While(rs.next(){
sbean = new StdBean();
sbean.setStudentId(rs.getString("stdid"));
sbean.setLogStatus(true);
(or)
ps = con.prepareStatement("select * from student where stdid like ?");
ps.setString(1,a);
rs= ps.executeQuery();
While(rs.next(){
if (b.equals(rs.getString("password"))){
sbean = new StdBean();
sbean.setStudentId(rs.getString("stdid"));
sbean.setLogStatus(true);
break;
}
}
considering b as a run time argument.
if there is only one match it throws null pointer exception..
Edited by: joeemm on Aug 11, 2008 6:02 AM