本文介绍了“由查询返回多个结果集”的解决方案是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到错误:
ERROR [NewsDAO] findAll(): org.postgresql.util.PSQLException: Multiple ResultSets were returned by the query.
我使用postgresql-8.4-703.jdbc4.jar。
Im using 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;
}
我不知道为什么会收到此错误。有任何想法吗?
I don't know why i get this error. Any ideas?
推荐答案
您必须具有。
You must have multiple select statements in findAllQuery.toString()
.
Edit
Edit
正如JB Nizet指出的那样,您应该尝试从声明。 Postgresql JDBC驱动程序在分号上拆分语句,因此它可能发出两个语句。
As JB Nizet pointed out, you should try removing the semicolon from the statement. The Postgresql JDBC driver splits statements on the semicolon, so it may be issuing two statements.
这篇关于“由查询返回多个结果集”的解决方案是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!