-2
你好當我嘗試執行我的代碼,我得到錯誤:值java.sql.SQLException:結果集關閉
ERROR [TripDAO] TripDAO: findAllTripsByActivityId()
java.sql.SQLException: The result set is closed.
方法在那裏我得到錯誤的樣子:
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;
}
我有不知道這段代碼中可能會出現什麼錯誤。你可以幫我嗎?
你會打印整個堆棧跟蹤嗎?也許底層流由於某種原因被關閉。 – 2012-04-02 19:03:09
在那個'...'的某個地方,你沒有發帖,你正在關閉結果集。 – 2012-04-02 19:07:09
對不起,我完全誤解了這個問題。 – everton 2012-04-02 19:45:25