「多個結果進行查詢返回」我得到的錯誤:什麼是溶液
ERROR [NewsDAO] findAll(): org.postgresql.util.PSQLException: Multiple ResultSets were returned by the query.
進出口使用PostgreSQL,8.4-703.jdbc4.jar。
我的代碼如下所示:
private static StringBuilder findAllQuery = new StringBuilder();
{
findAllQuery.append("SELECT * FROM news;");
}
public List<News> findAll() {
Statement stm = null;
ResultSet rs = null;
List<News> results = new ArrayList<News>();
if (obtainConnection()) {
try {
stm = con.createStatement();
rs = stm.executeQuery(findAllQuery.toString());
while(rs.next())
results.add(setInObject(rs));
} catch (Exception e) {
logger.error("findAll(): " + e);
} finally {
logger.info("Zamknalem");
closeConnection();
}
}
return results;
}
public News setInObject(ResultSet rs) throws SQLException {
News news = new News();
news.setId(rs.getInt("id"));
news.setTitle(rs.getString("title"));
news.setDescription(rs.getString("description"));
//TODO: timestamp
news.setDate(rs.getDate("date"));
User user = new User();
user.setId(rs.getInt("user_id"));
news.setUser(user);
news.setActive(rs.getBoolean("active"));
return news;
}
我不知道爲什麼我得到這個錯誤。有任何想法嗎?
而查詢是...? –
選擇*來自新聞; –
你可以發佈你實際創建/分配findAllQuery的代碼嗎? –