gpt4 book ai didi

java - "Multiple ResultSets were returned by the query"的解决方法是什么

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:43 25 4
gpt4 key购买 nike

我得到错误:

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;
}

我不知道为什么会出现此错误。有什么想法吗?

最佳答案

你必须有 multiple select statementsfindAllQuery.toString() 中。

编辑

正如 JB Nizet 指出的那样,您应该尝试从语句中删除分号。 Postgresql JDBC 驱动程序在分号处拆分语句,因此它可能发出两个语句。

关于java - "Multiple ResultSets were returned by the query"的解决方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10515260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com