why does the view return a null ? thanks in advance.
this is my view jsp
String abb = "ab";
String cdd = "cd";
UserPass user = UserDb.selectUser(abb,cdd);
out.println(user);
and this is my UserPass class
public class UserPass {
String username;
String password;
public UserPass(){
this.username ="";
this.password ="";
}
public void setUserName(String username) {
this.username = username;
}
public String getUserName(){
return username;
}
}
and finally the data package, UserDb
String query = "select user_name from UserPass where user_name = ? AND user_password = ? " ;
try{
ps = connection.prepareStatement(query);
ps.setString(1, username);
ps.setString(2, password);
rs = ps.executeQuery();
if (rs.getString("user_name") != null) {
UserPass up = new UserPass();
up.setUserName(rs.getString("user_name"));
return up;
} else {
return null;
}
}
My database is simple and the entries are there user_name and user_password. The view returns null
You need to use rs.next() to check if the current row is valid first: