当我尝试执行我的代码时,我收到错误:
错误[TripDAO] TripDAO:findAllTripsByActivityId()
java.sql.SQLException:结果集已关闭。
我收到错误的方法如下:
public List<Trip> findAllTripsByActivityId(int id) {
List<Trip> trips = new ArrayList<Trip>();
if (obtainConnection()) {
try {
PreparedStatement stm = null;
ResultSet rs = null;
stm = con.prepareStatement(findAllTripsByActivityIdQuery
.toString());
logger.info("Wybrano id: " + id);
stm.setInt(1, id);
rs = stm.executeQuery();
while (rs.next()) {
trips.add(setInObject(rs));
}
} catch (Exception e) {
logger.error("TripDAO: findAllTripsByActivityId() " + e);
} finally {
closeConnection();
}
}
return trips;
}
public Trip setInObject(ResultSet rs) throws SQLException {
Trip trip = new Trip();
int id = rs.getInt("id");
trip.setId(id);
...
return trip;
}
我不知道这段代码可能出错了什么。你能救我吗?
答案 0 :(得分:0)
您正在将整个ResultSet传递给setInObject
方法,这可能会破坏它。尝试从findAllTripsByActivityId
方法中的结果集中提取值。