Oracle Update批处理模型-在同一应用程序中使用两种批处理模型 [英] Oracle Update Batching Models - Using both batching models in same application

查看:267
本文介绍了Oracle Update批处理模型-在同一应用程序中使用两种批处理模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Oracle JDBC支持两种不同的更新批处理模型:标准批处理和Oracle特定批处理.

Oracle JDBC supports two distinct models for update batching: Standard Batching and Oracle Specific Batching.

根据《 Oracle 11g JDBC开发人员指南》,在任何单个应用程序中,都可以使用一个模型或另一个模型,但不能同时使用两个模型.当您混合这些异常时,Oracle JDBC驱动程序将引发异常.

According to oracle 11g JDBC Developer Guide, in any single application, you can use one model or the other, but not both. Oracle JDBC driver will throw exceptions when you mix these.

在我的独立应用程序中,以上陈述不成立.我想知道我是否想念一些东西.

In my standalone application, the above statement does not hold true. I want to know if I am missing something.

在我的应用程序中,我创建一个OracleDataSource并执行以下操作

In my application I create a OracleDataSource and do the following


    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();
    }

上面的代码运行良好,我可以看到使用不同批处理模型的两个更新批处理都执行得很好.有什么我错过的东西,或者我对jdbc开发人员指南的解释不正确吗?

The above code runs well and I could see both the update batches using different batching models getting executed well. Is there anything which I missed out or my interpretation of jdbc developer guide is incorrect?

预先感谢

推荐答案

是的,他们写出了真相:-) 但这很适合一个 PreparedStatement实例

Yes, they write the truth :-) But this aply to one instance of PreparedStatement

我查看了OraclePreparedStatement的反编译源:

I looked at decompile sources of 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

So, they realy check mixing of batch modes for instance of OraclePreparedStatement

这篇关于Oracle Update批处理模型-在同一应用程序中使用两种批处理模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆