gpt4 book ai didi

java - 使用executeQuery时出现NullPointerException

转载 作者:行者123 更新时间:2023-12-01 06:29:04 26 4
gpt4 key购买 nike

我有一个空指针异常

ResultSet rs = aStatement.executeQuery(Query); // it can't be executed 

我的代码是这样的:

 public static boolean testLogin(String user, String password) throws SQLException {
String Query = "select * from TBL_Users where userName = '" + user + "' and passWord = '" + password + "' ";
ResultSet rs = aStatement.executeQuery(Query);

while (rs.next()) {

info.Id = rs.getInt("ID");
info.userName = rs.getString("userName");
info.Name = rs.getString("User_Name");
info.Password = rs.getString("passWord");
info.isAdmin = rs.getBoolean("Admin");
return true;
}
return false;
}

}

最佳答案

很可能aStatement为空。

关于java - 使用executeQuery时出现NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4518764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com