java.sql.SQLRecoverableException : Closed Connection; State=08003; ErrorCode=17008

标签 java jboss oracle11g database-connection connection-close

使用循环 java 在 Oracle 数据库表中插入一些行时出现以下错误,我的循环将执行近 25000 次:

java.sql.SQLRecoverableException: Closed Connection; State=08003; ErrorCode=1700
    8
            at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnec
    tion.java:3331)
            at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxy
    Connection.java:275)
            at org.compiere.db.PreparedStatementProxy.init(PreparedStatementProxy.ja
    va:71)
            at org.compiere.db.PreparedStatementProxy.<init>(PreparedStatementProxy.
    java:44)
            at org.compiere.db.ProxyFactory.newCPreparedStatement(ProxyFactory.java:
    54)
            at org.compiere.util.DB.executeUpdate(DB.java:1007)
            at org.compiere.util.DB.executeUpdate(DB.java:877)
            at org.compiere.util.DB.executeUpdate(DB.java:864)
            at org.compiere.report.FinReport.insertLineSource(FinReport.java:1033)
            at org.compiere.report.FinReport.insertLineDetail(FinReport.java:844)
            at org.compiere.report.FinReport.doIt(FinReport.java:306)
            at org.compiere.process.SvrProcess.process(SvrProcess.java:147)
            at org.compiere.process.SvrProcess.startProcess(SvrProcess.java:105)

下面是我的代码:

private void insertLineSource (int line)
{
    log.info("Line=" + line + " - " + m_lines[line]);

    //  No source lines
    if (m_lines[line] == null || m_lines[line].getSources().length == 0)
        return;
    String variable = m_lines[line].getSourceColumnName();
    if (variable == null)
        return;
    log.fine("Variable=" + variable);

    //  Insert
    StringBuffer insert = new StringBuffer("INSERT INTO T_Report "
        + "(AD_PInstance_ID, PA_ReportLine_ID, Record_ID,Fact_Acct_ID,LevelNo ");
    for (int col = 0; col < m_columns.length; col++)
        insert.append(",Col_").append(col);
    //  Select
    insert.append(") SELECT ")
        .append(getAD_PInstance_ID()).append(",")
        .append(m_lines[line].getPA_ReportLine_ID()).append(",")
        .append(variable).append(",0,");
    if (p_DetailsSourceFirst)
        insert.append("-1 ");
    else
        insert.append("1 ");

    //  for all columns create select statement
    for (int col = 0; col < m_columns.length; col++)
    {
        insert.append(", ");
        //  No calculation
        if (m_columns[col].isColumnTypeCalculation())
        {
            insert.append("NULL");
            continue;
        }

        //  SELECT SUM()
        StringBuffer select = new StringBuffer ("SELECT ");
        if (m_lines[line].getPAAmountType() != null)                //  line amount type overwrites column
            select.append (m_lines[line].getSelectClause (true));
        else if (m_columns[col].getPAAmountType() != null)
            select.append (m_columns[col].getSelectClause (true));
        else
        {
            insert.append("NULL");
            continue;
        }

        if (p_PA_ReportCube_ID > 0) {
            select.append(" FROM Fact_Acct_Summary fb WHERE DateAcct ");
        }  //report cube
        else {
        //  Get Period info
            select.append(" FROM Fact_Acct fb WHERE TRUNC(DateAcct, 'DD') ");
        }
        FinReportPeriod frp = getPeriod (m_columns[col].getRelativePeriod());
        if (m_lines[line].getPAPeriodType() != null)            //  line amount type overwrites column
        {
            if (m_lines[line].isPeriod())
                select.append(frp.getPeriodWhere());
            else if (m_lines[line].isYear())
                select.append(frp.getYearWhere());
            else if (m_lines[line].isNatural())
                select.append(frp.getNaturalWhere("fb"));
            else
                select.append(frp.getTotalWhere());
        }
        else if (m_columns[col].getPAPeriodType() != null)
        {
            if (m_columns[col].isPeriod())
                select.append(frp.getPeriodWhere());
            else if (m_columns[col].isYear())
                select.append(frp.getYearWhere());
            else if (m_columns[col].isNatural())
                select.append(frp.getNaturalWhere("fb"));
            else
                select.append(frp.getTotalWhere());
        }
        //  Link
        select.append(" AND fb.").append(variable).append("=x.").append(variable);
        //  PostingType
        if (!m_lines[line].isPostingType())     //  only if not defined on line
        {
            String PostingType = m_columns[col].getPostingType();
            if (PostingType != null && PostingType.length() > 0)
                select.append(" AND fb.PostingType='").append(PostingType).append("'");
            // globalqss - CarlosRuiz
            if (PostingType.equals(MReportColumn.POSTINGTYPE_Budget)) {
                if (m_columns[col].getGL_Budget_ID() > 0)
                    select.append(" AND GL_Budget_ID=" + m_columns[col].getGL_Budget_ID());
            }
            // end globalqss
        }
        //  Report Where
        String s = m_report.getWhereClause();
        if (s != null && s.length() > 0)
            select.append(" AND ").append(s);
        //  Limited Segment Values
        if (m_columns[col].isColumnTypeSegmentValue())
            select.append(m_columns[col].getWhereClause(p_PA_Hierarchy_ID));

        //  Parameter Where
        select.append(m_parameterWhere);
    //  System.out.println("    c=" + col + ", l=" + line + ": " + select);
        //
        insert.append("(").append(select).append(")");
    }
    //  WHERE (sources, posting type)
    StringBuffer where = new StringBuffer(m_lines[line].getWhereClause(p_PA_Hierarchy_ID));
    String s = m_report.getWhereClause();
    if (s != null && s.length() > 0)
    {
        if (where.length() > 0)
            where.append(" AND ");
        where.append(s);
    }
    if (where.length() > 0)
        where.append(" AND ");
    where.append(variable).append(" IS NOT NULL");

    if (p_PA_ReportCube_ID > 0)
        insert.append(" FROM Fact_Acct_Summary x WHERE ").append(where);
    else
    //  FROM .. WHERE
    insert.append(" FROM Fact_Acct x WHERE ").append(where);    
    //
    insert.append(m_parameterWhere)
        .append(" GROUP BY ").append(variable);

    int no = DB.executeUpdate(insert.toString(), get_TrxName());
    if (CLogMgt.isLevelFinest())
        log.fine("Source #=" + no + " - " + insert);
    if (no == 0)
        return;

    //  Set Name,Description
    StringBuffer sql = new StringBuffer ("UPDATE T_Report SET (Name,Description)=(")
        .append(m_lines[line].getSourceValueQuery()).append("T_Report.Record_ID) "
        //
        + "WHERE Record_ID <> 0 AND AD_PInstance_ID=").append(getAD_PInstance_ID())
        .append(" AND PA_ReportLine_ID=").append(m_lines[line].getPA_ReportLine_ID())
        .append(" AND Fact_Acct_ID=0");
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (CLogMgt.isLevelFinest())
        log.fine("Name #=" + no + " - " + sql.toString());

    if (m_report.isListTrx())
        insertLineTrx (line, variable);
}   //  insertLineSource

最佳答案

应用程序代码不应将缓存的连接句柄从数据访问客户端的一个实例传递到另一客户端实例。在客户端实例之间传输连接句柄会导致一个实例使用另一个实例引用的连接句柄而产生问题。 例如,当接收传输句柄的客户端实例的应用程序代码关闭该句柄并且保留对该句柄的原始引用的客户端实例尝试回收该句柄时,应用程序服务器会发出异常。 显示了本例中预期的一些异常(exception)情况。 异常描述:清理 ManagedConnection 进行销毁操作时检测到异常。引用数据库软件报告的错误,有助于确定错误原因。 异常

0000004d WSRdbManagedC W   DSRA0180W: Exception detected during 
ManagedConnection.destroy().  The exception is:  
com.ibm.ws.exception.WsException: DSRA0080E: An exception was received by 
 the Data Store Adapter Invalid operation: Connection is closed. ERRORCODE=- 
4470, SQLSTATE=08003. With SQL State: 08003 SQL Code : -4470

阅读this对于更多不理解的事情

关于java.sql.SQLRecoverableException : Closed Connection; State=08003; ErrorCode=17008,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20284608/

相关文章:

java - 在java中使用CDI注入(inject)多个log4j记录器类型

java - Synth 外观和感觉没有执行任何操作?

java - 为什么 MenuItemCompat.getActionProvider 返回 null?

java - Java 线程类的返回值

tomcat - 是否有在 JBoss AS7 中使用 WebSockets 的示例?

sql - ORA-29024 : Certificate validation failure

sql - Oracle 数字字符串列和索引

java - 绕过 Hibernate 中的 GeneratedValue

ios - SSL - 在 iOS7 中表现不同?

ruby-on-rails - 在不删除测试数据库的情况下运行 Rails 测试