Oracle 准备好的语句-执行批处理,即使一行有错误,整个批处理也会失败

Oracle 准备好的语句-执行批处理,即使一行有错误,整个批处理也会失败,oracle,jdbc,prepared-statement,batch-processing,Oracle,Jdbc,Prepared Statement,Batch Processing,我有一个问题,当我在批处理中有一个重复的行时,我的执行批处理对此行失败,但问题是其余的insert语句没有执行。我使用Oracle SQL驱动程序主要版本JDBC 4 我如何确保至少执行了无错误的行,并且没有插入有错误的数据行 conn.setAutoCommit(true); try { PreparedStatement testStatement = conn.prepareStatement("insert into EW_JOBS.jhi_job_history v

我有一个问题,当我在批处理中有一个重复的行时,我的执行批处理对此行失败,但问题是其余的insert语句没有执行。我使用Oracle SQL驱动程序主要版本JDBC 4

我如何确保至少执行了无错误的行,并且没有插入有错误的数据行

  conn.setAutoCommit(true);
    try {
    PreparedStatement testStatement = conn.prepareStatement("insert into EW_JOBS.jhi_job_history values (?,?,?,?,?,?,?,?,?,?)" );





    testStatement.setInt(1, 4477443);
    testStatement.setInt(2, 4477443);
    testStatement.setDate(3, null);
    testStatement.setString(4, null);
    testStatement.setString(5, null);
    testStatement.setString(6, null);
    testStatement.setString(7, null);
    testStatement.setString(8, null);
    testStatement.setString(9, null);
    testStatement.setString(10, null);
    testStatement.addBatch();
    testStatement.setInt(1, 4477444);
    testStatement.setInt(2, 4477444);
    testStatement.setDate(3, null);
    testStatement.setString(4, null);
    testStatement.setString(5, null);
    testStatement.setString(6, null);
    testStatement.setString(7, null);
    testStatement.setString(8, null);
    testStatement.setString(9, null);
    testStatement.setString(10, null);

    testStatement.addBatch();

    testStatement.setInt(1, 4477443);
    testStatement.setInt(2, 4477443);
    testStatement.setDate(3, null);
    testStatement.setString(4, null);
    testStatement.setString(5, null);
    testStatement.setString(6, null);
    testStatement.setString(7, null);
    testStatement.setString(8, null);
    testStatement.setString(9, null);
    testStatement.setString(10, null);

    testStatement.addBatch();

    testStatement.setInt(1, 4477445);
    testStatement.setInt(2, 4477445);
    testStatement.setDate(3, null);
    testStatement.setString(4, null);
    testStatement.setString(5, null);
    testStatement.setString(6, null);
    testStatement.setString(7, null);
    testStatement.setString(8, null);
    testStatement.setString(9, null);
    testStatement.setString(10, null);
    testStatement.addBatch();

    testStatement.setInt(1, 4477446);
    testStatement.setInt(2, 4477446);
    testStatement.setDate(3, null);
    testStatement.setString(4, null);
    testStatement.setString(5, null);
    testStatement.setString(6, null);
    testStatement.setString(7, null);
    testStatement.setString(8, null);
    testStatement.setString(9, null);
    testStatement.setString(10, null);

    testStatement.addBatch();



    testStatement.executeBatch();
    conn.commit();
    conn.close();
    }
    catch (BatchUpdateException e) {


       System.out.println("update counts value is : " +e.getUpdateCounts());

    }

请张贴您的密码。您是否禁用了自动提交?最初是的,但它也不适用于autocommit true。理想情况下,我希望即使在一行出现错误(在本例中是重复的)之后,批处理仍将继续。我如何才能做到这一点?是的,这是批量工作的方式。没有解决办法(除了不使用批插入)对不起,我误解了你的问题。故障是停止批处理的其余部分,还是继续执行其余语句的确切行为取决于驱动程序。JDBC允许驱动程序选择一个选项,但要求它始终如一地应用该选项。Oracle选择了“第一次出错时停止”的方法。这是不幸的。这有什么办法吗?我相信没有。