Students tempStudent = new Students();
thay đổi nó thành
Students tempStudent;
Bạn đang ghi đè overridding thuộc tính property of same object vì bạn đã tạo tempStudent outside while loop . Bạn phải thêm objects bằng number of record trong cơ sở dữ liệu. Vì vậy, hãy tạo đối tượng tempStudent như bên dưới.
sử dụng
while (rs.next()) {
tempStudent = new Students();
tempStudent.studentId = rs.getInt("StudentNo");
tempStudent.studentName = rs.getString("StudentName");
tempStudent.studentAge = rs.getInt("StudentAge");
students.add(tempStudent);
size++;
}