我继续测试此连接ResultSet
,而System.out.println(rs)
返回oracle.jdbc.driver.ForwardOnlyResultSet@2aa5fe93
System.out.println(rs.next())
给我虚假
我的输出是:
Exception in thread "main" java.lang.NullPointerException
at com.prjzr.Driver.main(Driver.java:31)
public class UserDaoImpl implements UserDao {
public List<User> getUser() {
// TODO Auto-generated method stub
List<User> users = new ArrayList<>();
String sql = "SELECT * FROM USERPROFILE";
try(Connection conn = DatabaseAccessUtil.getHardCodedConnection();
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery(sql);){
// System.out.println(rs);
while(rs.next()) {
int recNumber = rs.getInt("RECNUMBER");
String username = rs.getString("USERID");
String acctHldrFirstName = rs.getString("ACCOUNTHOLDERFIRSTNAME");
String acctHldrFirstLast = rs.getString("ACCOUNTHOLDERLASTNAME");
String acctHldrMailing = rs.getString("ACOUNTHOLDERMAILING");
String primaryAcctKey = rs.getString("PRIMARYACCTNUMBER");
String userPassword = rs.getString("PASSWORD");
users.add(new User(recNumber, username, acctHldrFirstName, acctHldrFirstLast, acctHldrMailing, primaryAcctKey, userPassword));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
我看过另一个问题,他们的问题与此问题略有不同。 如何读取我的记录并摆脱
Exception in thread "main" java.lang.NullPointerException
at com.prjzr.Driver.main(Driver.java:31)