0

I've been trying to loop through my resultSet but for some reason only the last object in my database is selected. The idea is that I already pulled my needed Section from my database and I now want to add objects to my secions array list.

e.g. I pulled a Section called "Guitar" with the SectionId 1 from my table Sections and now want to add all objects from my table sectionmitschueler where sectionid = 1 to section 1's arraylist.

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"));
        }
    }
}
this_is_cat
  • 138
  • 10
Rugo
  • 349
  • 1
  • 6
  • 14
  • Did you try to debug your code? By looking at your code you're missing parenthesis for the `if` statement, only the println is called when the condition is true, the line below is always called. – Amongalen Apr 24 '19 at 14:17
  • You are setting the value to sectionTO instance. I guess this should be to eineSectionTO. – James Jithin Apr 24 '19 at 14:26

0 Answers0