问题描述
我遇到了一些困惑的问题。我已经有了使用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;
}
解决方法
找到了答案,并在其他人遇到类似问题时发贴。发生的是,我的mysql表中的一行有一个条目(我认为已删除)与我要提取的类型不匹配。列表尝试声明一个int,但该行中的值为varchar。编辑了表格,使其是正确的类型。现在可以使用了^^