我的课上有这个方法,
public static AccountHolder getAccountHolder(String username, String password) {
try {
String verifyQuery = "SELECT COUNT(username) FROM accountholder WHERE username=? AND password=?)";
connection = getConnection();
ptmt = connection.prepareStatement(verifyQuery);
ptmt.setString(4, username);
ptmt.setString(5, password);
ResultSet verified = ptmt.executeQuery();
if (verified.next()) {
// Only one Result
if (verified.getInt(1) == 1) {
connection.close();
return 1;
} else {
connection.close();
return null;
}
}
} catch (Exception ex) {
}
}
我知道我应该返回 AccountHolder 类型的对象,它是一个类。AccountHolder 类代码如下:
public class AccountHolder {
private String firstname;
private String lastname;
private String username;
private String password;
private String address;
private String phonenumber;
// get & set methods();
}
我应该使用该方法从数据库返回匹配的用户名和密码。我怎样才能做到这一点?