[英]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: 好的,这时我们开始工作:
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.