【问题标题】:ResultSet not returning av values from selected tableResultSet 不返回所选表中的 av 值
【发布时间】:2020-12-02 05:23:03
【问题描述】:

我遇到了一个令人困惑的问题。我有一个使用 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;  
}

【问题讨论】:

  • } catch (Exception e) { e.printStackTrace(); }?
  • 帮助很大!快速简单,我喜欢。

标签: java mysql arraylist resultset


【解决方案1】:

找到答案,如果其他人遇到类似问题,请发布。发生的事情是我的 mysql 表中的一行有一个条目(我认为它已删除)与我试图提取的类型不匹配。该列表试图声明一个 int,但该行中的值为 varchar。编辑表格,使其类型正确。现在可以了^^

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    相关资源
    最近更新 更多