0

我在使用循环 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
4

4 回答 4

1

应用程序代码不应将缓存的连接句柄从数据访问客户端的一个实例传递到另一个客户端实例。在客户端实例之间传输连接句柄会导致一个实例使用另一个实例引用的连接句柄出现问题。例如,当接收到传输的句柄的客户端实例的应用程序代码关闭句柄并且保留对句柄的原始引用的客户端实例尝试回收它时,应用程序服务器会发出异常。显示了在这种情况下预期的一些异常。异常描述:清理 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

阅读内容以获得更多不确定性

于 2013-11-29T11:51:13.510 回答
0

PreparedStatement也许代码在打开数据库连接和准备之间,或者在其他数据库操作和准备下一个之间花费了太多时间PreparedStatement,以至于连接由于不活动而关闭。

连接可能由 Oracle 或 C3P0 关闭,因此请检查您的 C3P0 配置以了解超时设置。还可以考虑在稍后的执行中获取连接。

于 2013-11-30T11:49:28.027 回答
0

也许您在 C3P0 中遇到了与 Oracle 连接相关的错误。

于 2013-11-30T11:51:13.270 回答
0

可能您在连接到数据库实例时遇到了短暂的网络错误(假设数据库位于另一台计算机上;如果数据库位于同一台计算机上,则不会出现这种情况)。

为了避免这个问题停止执行,你应该捕获这样RecoverableException的s,从连接池中获取一个新的连接,然后重试数据库操作。

于 2013-11-30T11:52:42.650 回答