private void findChildren() { childList.clear(); try (Connection con = ds.getConnection()) { // Student student = studentdao.findByID(selectedStudent); Map<String, List<String>> map = savaildao.findByID(selectedStudent); String sql = findChildrenSQL(); try (PreparedStatement find = con.prepareStatement(sql)) { // Map<String, List<String>> map = student.getDaymap(); for (Map.Entry<String, List<String>> entry : map.entrySet()) { find.setString(1, entry.getKey()); List<String> list = entry.getValue(); // loop through the list for (int i = 0; i < list.size(); i++) { find.setString(2, list.get(i)); try (ResultSet rs = find.executeQuery()) { while (rs.next()) { Child child = childdao.findByID(rs.getLong("childid")); // make sure it's not already a part of the list if (childList.isEmpty()) { childList.add(child); } else for (int j = 0; j < childList.size(); j++) { if (childList.get(j).getChildID() == child.getChildID()) break; if (j == childList.size() - 1) { childList.add(child); break; } } } } } } } } catch (SQLException ex) { Logger.getLogger(AdminPairing.class.getName()).log(Level.SEVERE, null, ex); System.err.println(ex.getMessage()); } }