2013-03-06 278 views
0

我有一個比較簡單的portlet,它顯示門戶(在線,每天,每週,每月,每年)的訪問者數量。com.ibm.db2.jcc.am.SqlException:無效操作:結果集關閉。 ERRORCODE = -4470,SQLSTATE = null

在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. 

搜索我仍然沒有發現互聯網之後/意識到了什麼是我的情況下,錯誤的原因,以及如何我可以修復它。任何幫助,將不勝感激。

回答

0

我得到相同錯誤的原因是因爲我關閉了db2連接,然後嘗試讀取結果集。請強調一下,在讀取結果集時,db2必須保持連接狀態。

相關問題