使用AutoGeneratedKeys和Oracle时出现ArrayIndexOutOfBoundsException [英] ArrayIndexOutOfBoundsException when use AutoGeneratedKeys and Oracle

查看:331
本文介绍了使用AutoGeneratedKeys和Oracle时出现ArrayIndexOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下情况下使用ojdbc6-11.1.0.7.0:

I use ojdbc6-11.1.0.7.0 and when:

ps = connection.prepareStatement("Insert into A (b, C) values (?, ?)", Statement.RETURN_GENERATED_KEYS);

我知道

java.lang.ArrayIndexOutOfBoundsException: 3
    at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:950)
    at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:623)
    at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:1212)
    at oracle.jdbc.driver.T4CPreparedStatement.<init>(T4CPreparedStatement.java:28)
    at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:68)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3140)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3042)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5890)

我只是在此处上了解了此错误,但是解决方案没有帮助,因为我使用Statement.RETURN_GENERATED_KEYS功能.

I just read about this bug here, but solution does not help because I use Statement.RETURN_GENERATED_KEYS feature.

还有其他解决方法吗?

推荐答案

好,我们现在开始工作:

Ok at this time we make workarount:

  • 插入不带语句的RETURN_GENERATED_KEYS
  • 因为我们使用序列生成ID,所以添加了以下附加查询:

  • insert without Statement.RETURN_GENERATED_KEYS
  • because we use sequence to generate ids add additional query that:

select seq.currval from dual

那很好,但是我们没有很多用户,而且该解决方案也不能防止多线程问题(我们可能会得到错误的ID).

That works fine but we dont have many users and this solution dont protect against multithread problems (we can get wrong Id).

这篇关于使用AutoGeneratedKeys和Oracle时出现ArrayIndexOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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