为什么视图返回 null ?提前致谢。
这是我的观点jsp
String abb = "ab";
String cdd = "cd";
UserPass user = UserDb.selectUser(abb,cdd);
out.println(user);
这是我的 UserPass 课程
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;
}
}
最后是数据包,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;
}
}
我的数据库很简单,条目是 user_name 和 user_password。视图返回 null