首页 > 解决方案 > 遍历 resultSet 只给出表中的最后一个对象

问题描述

我一直在尝试遍历我的resultSet但由于某种原因只选择了我数据库中的最后一个对象。这个想法是我已经从我的数据库中提取了我需要的部分,我现在想将对象添加到我的部分数组列表中。

SectionId 1例如,我从表中提取了一个名为“Guitar”的部分Sections,现在想将表sectionmitschueler中的所有对象添加sectionid = 1到部分 1 的数组列表中。

resultSet = Persistence.executeQueryStatement(aConnection, "SELECT * "
    + "FROM sectionmitschueler");
while (resultSet.next()) {
    for(SectionTO eineSectionTO : eventTO.getSections()) {
        if(resultSet.getInt("sectionId") == eineSectionTO.getSectionId())
            System.out.println(sectionTO.getSectionId());
            sectionTO.getSchueler().add(resultSet.getInt("schuelerId"));
        }
    }
}

标签: javasqlloopsfxmlresultset

解决方案


推荐阅读