What is a solution of “Multiple ResultSets were returned by the query”

烈酒焚心 提交于 2020-01-14 09:32:58

问题


I get error:

ERROR [NewsDAO] findAll(): org.postgresql.util.PSQLException: Multiple ResultSets were returned by the query.

Im using postgresql-8.4-703.jdbc4.jar.

My code looks like:

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?


回答1:


You must have multiple select statements in findAllQuery.toString().

Edit

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.



来源:https://stackoverflow.com/questions/10515260/what-is-a-solution-of-multiple-resultsets-were-returned-by-the-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!