나는 학교에서 자바를 배우기 때문에 어떤 이유로 아래 코드가 결과를 반환하지 않습니까? 이 코드에 문제가 있습니까? 12이 쿼리가 결과를 반환하지 않는 이유는 무엇입니까?
public static ResultSet GetByID(int studentID) {
// This method loads the mysql driver and establishes the database connection
Connect();
ResultSet results = null;
try {
String query = "SELECT * FROM student where studentID = ?";
PreparedStatement statement = Connection.prepareStatement(query);
statement.setInt(1, studentID);
results = statement.executeQuery();
} catch (SQLException ex) {
LogException(ex);
} catch (Exception ex) {
System.out.println(ex);
}
// This method terminates the mysql connection.
Disconnect();
return results;
}
호출 코드 (int(10)
임) studentID
와 MySQL 데이터베이스에서 하나의 기록이있다이다 :
@Override
public ResultSet query() {
return DB.GetByID(getStudentID()); // this is 12
}
이 아니라 단지 빈, null을 반환하지 않습니다 결과 집합입니다.
studentID == 10이고 throw되는 예외가 없다고 가정한다고 가정합니다. – cwallenpoole
오류/예외가 발생하고 있습니까? 그렇지 않다면 사용중인 학생 ID가 데이터 바에 있습니까? – Waqas
나는 체크하고 정상적으로 리턴한다. 그러나 이것으로부터 리턴 된 ResultSet을 읽을 때 레코드가 없다. catch 블록 중 하나에 속하지 않습니다. – Eli