I'm trying to create a for cycle with a dynamic sql statement:
for(int i = 0; i < size; i++) {
ps2 = db.prepareStatement("select * from student where id=?");
ps2.setInt(1,studList[i]);
rs2=ps2.executeQuery();
while(rs2.next()){
list1.add(new Student(rs2.getInt("id"), rs2.getString("name"), rs2.getString("city"));
}
rs2.close();
ps2.close();
}
studList[i] is an array with all the student ID and the variable "size" is the length of this array. The problem with this code is that only one element is added to the list(corresponding to the first student ID). I noticed that the code goes inside 'while(rs2.next())' just if the value of studList[i] doesn't change. Why?