简体   繁体   English

使用AutoGeneratedKeys和Oracle时出现ArrayIndexOutOfBoundsException

[英]ArrayIndexOutOfBoundsException when use AutoGeneratedKeys and Oracle

I use ojdbc6-11.1.0.7.0 and when: 我在以下情况下使用ojdbc6-11.1.0.7.0:

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

I get 我懂了

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)

I just read about this bug here , but solution does not help because I use Statement.RETURN_GENERATED_KEYS feature. 我只是在这里阅读有关此错误的信息 ,但解决方案没有帮助,因为我使用了Statement.RETURN_GENERATED_KEYS功能。

Is there any other solution? 还有其他解决方案吗?

Ok at this time we make workarount: 好的,这时我们开始工作:

  • insert without Statement.RETURN_GENERATED_KEYS 插入不带Statement.RETURN_GENERATED_KEYS
  • because we use sequence to generate ids add additional query that: 因为我们使用序列生成ID,所以添加了以下附加查询:

     select seq.currval from dual 

That works fine but we dont have many users and this solution dont protect against multithread problems (we can get wrong Id). 效果很好,但是我们没有很多用户,而且此解决方案也无法防止多线程问题(我们可能得到错误的ID)。

尝试ps = connection.prepareStatement(“插入A(b,C)值(?,?)”,Statement.RETURN_GENERATED_KEYS);

Please use ojdbc6.jar (rather than ojdbc6_g.jar) from oracle. 请从oracle使用ojdbc6.jar (而不是ojdbc6_g.jar)。 It will solve this problem. 它将解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Servlet中使用getParameterValues时的ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException when use getParameterValues in Servlet 当我使用`mvn hpi:run`时有一个ArrayIndexOutOfBoundsException - There is a ArrayIndexOutOfBoundsException when I use `mvn hpi:run` 创建与Oracle数据库的连接时出现java.lang.ArrayIndexOutOfBoundsException - java.lang.ArrayIndexOutOfBoundsException when creating a connection to an Oracle database 获取ArrayIndexOutOfBoundsException:2当我使用不同的分隔符分割字符串时 - Getting an ArrayIndexOutOfBoundsException: 2 When I use different delimiters for splitting strings ArrayIndexOutOfBoundsException-设置columnHeaders时 - ArrayIndexOutOfBoundsException - when setting columnHeaders .length为零时,ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException when .length is zero ArrayIndexOutOfBoundsException: 1 调用 getWindowHandles() 时 - ArrayIndexOutOfBoundsException: 1 when invoking getWindowHandles() 改组LinkedList时发生ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException when shuffling a LinkedList 选择行时ArrayIndexOutOfBoundsException(-1) - ArrayIndexOutOfBoundsException (-1) when selecting a row 操纵ArrayAdapter时出现ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException when manipulating ArrayAdapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM