Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Login Validation with JDBC

843859Aug 11 2008 — edited Aug 12 2008
When 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 9 2008
Added on Aug 11 2008
7 comments
195 views