我靠学校的一些Java,出于某种原因下面的代码不返回任何结果?这段代码有问题吗?有在MySQL数据库中的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;
}
调用代码的单个记录,具有studentID
(这是int(10)
)是:
@Override
public ResultSet query() {
return DB.GetByID(getStudentID()); // this is 12
}
这不返回null,而只是一个空结果集。
假设你确定studentID == 10,并且没有抛出异常吗? – cwallenpoole
您是否收到任何错误/异常?如果不是,那么您使用的学生证是否存在于数据库E中? – Waqas
我已检查并正常返回,但是当我读取从此返回的ResultSet时,没有记录。它不属于任何一个catch块。 – Eli