【问题标题】:com.ibm.db2.jcc.am.SqlException: Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=nullcom.ibm.db2.jcc.am.SqlException:无效操作:结果集已关闭。错误代码=-4470,SQLSTATE=null
【发布时间】:2013-02-20 18:22:58
【问题描述】:

我有一个相当简单的 portlet,它显示门户网站的访问者数量(在线、每日、每周、每月、每年)。

在 doView 方法中的 portlet 类中,首先我调用一个方法来插入表(有关新访问者的信息)。在我一一调用 5 个方法后,它们在同一张表上进行计数选择。它们都非常相似,只是它们的查询不同。其中一种方法实现如下:

public static Integer getOnline() {
    Integer res = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {
        stmt = getConnection().createStatement();
        rs = stmt.executeQuery(query);
        if (rs.next()) {
           res = new Integer(rs.getString("1"));
        }
    } catch (SQLException e) {
        log.error("Excepton: " + e);
    } finally {
        if (rs != null) {
            try { rs.close(); } catch (SQLException e) { log.warn("Error closing result set: ", e); }
            rs = null;
        }

        if (stmt != null) {
            try { stmt.close(); } catch (SQLException e) { log.warn("Error closing statement: ", e); }
            stmt = null;
        }
    }

    return res;
}

获得连接:

public static Connection getConnection() {
    try {
        if (connection == null) {
            if (dataSource == null) {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceName);
            }

            connection = dataSource.getConnection();
        }
    } catch (Exception e) {
        log.error("Error on opening a connection: ", e);
    }

    return connection;
}

连接在 doView 方法结束时关闭。有时我会遇到这种异常:

com.ibm.db2.jcc.am.SqlException: [jcc][t4][10120][10898][4.14.88] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null

从一种或几种方法中选择。有时还会出现以下错误:

com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Connection is closed.

com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Statement is closed.

在互联网上搜索后,我仍然没有找到/意识到在我的案例中出现错误的原因以及如何解决它。任何帮助将不胜感激。

【问题讨论】:

    标签: java db2 websphere-7


    【解决方案1】:

    将 resultSetHoldability 设置为driver 级别或preparing 您的语句。这应该可以解决您遇到的问题。

    【讨论】:

      【解决方案2】:

      我得到同样错误的原因是因为我关闭了 db2 连接,然后尝试读取结果集。请强调 db2 在读取结果集时必须保持连接这一事实。

      【讨论】:

        猜你喜欢
        • 2015-07-20
        • 2012-12-31
        • 1970-01-01
        • 1970-01-01
        • 2013-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多