Im confused as when i add code inside a loop it stops the looping (effectivly ending after the first round).
Code which is working fine
StringBuilder sb = new StringBuilder(4096);
while ((rs.next())) {
System.err.println(rs.getRow());
sb.append(rs.getString(1)).append(",");
}
writeToCell(sheet,"P",row.getRowNum()+1,sb.toString());
Code which doesnt loop
StringBuilder sb = new StringBuilder(4096);
while ((rs.next())) {
System.err.println(rs.getRow());
String p=rs.getString(1);
ArrayList<Parent> pscore = new ArrayList();
pscore.add(new Parent(p));
String Score= getSegment(pscore);
sb.append(p).append("(").append(Score).append("),");
}
writeToCell(sheet,"P",row.getRowNum()+1,sb.toString());
I cant figure out why it would loop in the top version and not the bottom version. No errors are thrown
My guess is that
performs a database query which replaces the
rswhich has finished before getSegment returns so the next call tors.next()will be false.To avoid this I would make sure that
rsis a local variable instead of a field.If this is the case, the best solution is likely to make the original SELECT a join between the tables so that is has all the information you need rather than performing a query per row.