java.sql.SQLException: 不允许的操作: operation cannot be mixed with Oracle-style batching 解决方案

我的开发环境是Eclipse helios,Tomcat 6以及JDK 1.6

使用的JDBC的jar包是ojdbc6.jar。使用TOMCAT设置的JNDI,通过JDBC访问Oracle数据,其中Tomcat的context.xml说明如下:

<Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver"
maxActive="100" maxIdle="30" maxWait="10000" name="cbs" password="*****"
type="javax.sql.DataSource" url="jdbc:oracle:thin:@*******:1521:****"
username="*****" />

Web.XML配置如下:

<resource-ref>
  <description>DB Connection</description>   
<res-ref-name>*****</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

 

在项目中只要是代码用到了PreparedStatement .addBatch和ExecuteBatch(),就会报下面的错误:

java.sql.SQLException: 不允许的操作: operation cannot be mixed with Oracle-style batching
at oracle.jdbc.driver.OraclePreparedStatement.setJdbcBatchStyle(OraclePreparedStatement.java:10122)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10343)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)

 

经过Baidu的搜索,包括设置了一些下面这篇文章的

https://stackoverflow.com/questions/17810967/java-sql-sqlexception-operation-cannot-be-mixed-with-oracle-style-batching 

setDefaultExecuteBatch和defaultBatchValue 都不管用,于是想到能不用另外一种方法代替,所以在网络上搜索到executeUpdate()这个方法。

就没有在报"不允许的操作: operation cannot be mixed with Oracle-style batching",暂时用这个方法解决了。

关于exceuteBatch和executeUpdate可以参考下面这篇文章

https://www.mkyong.com/jdbc/jdbc-preparedstatement-example-batch-update/ 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我还要去追逐我的梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值