Fix database selectStudentsFromCourse() bug

This commit is contained in:
2022-06-11 01:44:38 +08:00
parent b109d63607
commit dda818af2e
2 changed files with 9 additions and 1 deletions

View File

@@ -301,7 +301,9 @@ public class DatabaseHelper {
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setLong(1, courID);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
students.add(StudentOA.select(resultSet.getLong("stuID")));
while (resultSet.next()) {
students.add(StudentOA.select(resultSet.getLong("stuID")));
}
}
}
}

View File

@@ -2,6 +2,7 @@ package com.cfive.classroom.library.database;
import com.cfive.classroom.library.database.bean.Faculty;
import com.cfive.classroom.library.database.util.AlreadyExistsException;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.InsertException;
import com.cfive.classroom.library.database.util.NoConfigException;
import org.apache.logging.log4j.LogManager;
@@ -74,6 +75,11 @@ public class DatabaseTest {
DatabaseHelper.selectAllFromStudent().forEach(LOGGER::debug);
}
@Test
void selectStudentsFromCourseTest() throws NoConfigException, SQLException, DependenciesNotFoundException {
DatabaseHelper.selectStudentsFromCourse(2).forEach(LOGGER::debug);
}
@Test
void TempTest() {
LOGGER.debug(String.valueOf(UUID.randomUUID()));