2

Oracle JDBCは、更新バッチの2つの異なるモデルをサポートしています。標準バッチとOracle固有のバッチです。

oracle 11g JDBC開発者ガイドによると、単一のアプリケーションでは、どちらか一方のモデルを使用できますが、両方を使用することはできません。これらを混在させると、OracleJDBCドライバは例外をスローします

私のスタンドアロンアプリケーションでは、上記のステートメントは当てはまりません。何か足りないものがないか知りたいです。

私のアプリケーションでは、OracleDataSourceを作成し、次のことを行います


    connection = datasource.getConnection();
    preparedStatement = connection.prepareStatement("update CAR set CAR_NAME=?, OBJECT_VERSION=? where CAR_ID=?");
    for(Car car : cars) {
       preparedStatement.setString(1, car.getName());
       preparedStatement.setInt(2, car.getVersion() + 1);
       preparedStatement.setLong(3, car.getId());
       preparedStatement.addBatch();
    }

System.out.println("Update Batch : " + Arrays.toString(preparedStatement.executeBatch())); for(Car car : cars) { car.setName("v car " + car.getId()); } //Oracle Update Batching connection.setAutoCommit(false); PreparedStatement preparedStatement = connection.prepareStatement("update CAR set CAR_NAME=?, OBJECT_VERSION=? where CAR_ID=?"); //Change batch size for this statement to 3 ((OraclePreparedStatement)preparedStatement).setExecuteBatch (10); for(Car car : cars) { preparedStatement.setString(1, car.getName()); preparedStatement.setInt(2, car.getVersion() + 1); preparedStatement.setLong(3, car.getId()); System.out.println("Execute Update Count " + preparedStatement.executeUpdate()); } System.out.println("Update Count : " + ((OraclePreparedStatement)preparedStatement).sendBatch()); // JDBC sends the queued request connection.commit(); preparedStatement.close();

上記のコードは正常に実行され、異なるバッチモデルを使用した両方の更新バッチが正常に実行されていることがわかりました。見逃したものや、jdbc開発者ガイドの解釈が間違っているものはありますか?

前もって感謝します

4

1 に答える 1

2

はい、彼らは真実を書いています:-)しかし、これはPreparedStatementの1つのインスタンスに当てはまります

OraclePreparedStatementの逆コンパイルソースを調べました。

public void addBatch() throws SQLException {
  synchronized(connection){
    setJdbcBatchStyle();
    processCompletedBindRow(currentRank + 2, currentRank > 0 && sqlKind.isPlsqlOrCall());
    currentRank++;
  }
}

final void setJdbcBatchStyle() throws SQLException {
  if(m_batchStyle == 1){
        SQLException sqlexception =    DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 90, "operation cannot be mixed with Oracle-style batching");
        sqlexception.fillInStackTrace();
        throw sqlexception;
    } else{
        m_batchStyle = 2;
        return;
    }
}

したがって、OraclePreparedStatementのインスタンスのバッチモードの混合を実際にチェックします

于 2012-01-12T10:27:20.880 に答える