我遇到了一个令人困惑的问题。我有一个从表中提取数据的简单方法,使用SELECT *...但是,当它遍历该表时,它会在遍历完所述表中的所有条目之前停止迭代。在将行添加到ArrayList时,我已经使用了调试器来消除问题区域。但是,它仍然会在它应该停止之前停止。有什么想法吗?
public static ArrayList<Actors> acList() throws Exception {
ArrayList<Actors> acList = new ArrayList<Actors>();
try {
getConnection();
PreparedStatement st = conn.prepareStatement("SELECT * FROM Actors");
ResultSet rst = st.executeQuery();
Actors ac;
while (rst.next()) {
ac = new Actors(rst.getInt("ActorId"), rst.getString("fName"), rst.getString("eName"),
rst.getInt("Age"), rst.getInt("NoOfCredits"), rst.getString("Country"));
acList.add(ac);
}
} catch (Exception e) {
}
return acList;
}发布于 2020-08-12 21:17:35
找到了答案,如果其他人遇到类似的问题,就发帖子。发生的情况是,我的mysql表中有一行有一个条目(我认为它已经删除了),它的类型与我试图提取的类型不匹配。列表试图声明一个int,但行中的值是varchar。对表格进行了编辑,使其类型正确。现在它起作用了^^
https://stackoverflow.com/questions/63376897
复制相似问题