我正在尝试通过查询数据库来创建一个 UserInfo 对象构造函数,但我不断收到该部分的cannot find symbol
错误UserInfo thisUserInfo = new UserInfo()
。我正在尝试使用ResultSet rs
并填写构造函数来为登录的用户创建一个“会话”。
我在这里做错了什么?这是我的代码:
private UserInfo getUserInfo(HttpServletRequest request, HttpServletResponse response) throws SQLException {
String userName = request.getParameter("userName");
String nullString = null;
char nullChar = ' ';
ResultSet rs = null;
stmt = conn.createStatement();
String getInfoSQL = "SELECT * FROM " + studentsTable + " WHERE USERNAME = '" + userName + "'";
rs = stmt.executeQuery(getInfoSQL);
if(rs.next()) {
UserInfo thisUserInfo = new UserInfo(rs.getString(userName), rs.getString(passWord), rs.getString(lastName), rs.getString(firstName), rs.getString(age), rs.getString(sex), rs.getString(email));
rs.close();
stmt.close();
} else {
UserInfo thisUserInfo = new UserInfo(nullString, nullString, nullString, nullString, nullString, nullChar, nullString);
rs.close();
stmt.close();
}
return thisUserInfo;
}
这是我的 UserInfo 类:
public class UserInfo {
private final String userName;
private final String passWord;
private final String lastName;
private final String firstName;
private final String age;
private final char sex;
private final String email;
public UserInfo(String userName, String passWord, String lastName, String firstName, String age, char sex, String email) {
this.userName = userName;
this.passWord = passWord;
this.lastName = lastName;
this.firstName = firstName;
this.age = age;
this.sex = sex;
this.email = email;
}
public String getUserName() {
return this.userName;
}
public String getPassWord() {
return this.passWord;
}
public String getLastName() {
return this.lastName;
}
public String getFirstName() {
return this.firstName;
}
public String getAge() {
return this.age;
}
public char getSex() {
return this.sex;
}
public String getEmail() {
return this.email;
}
}