1

I use ojdbc6-11.1.0.7.0 and when:

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.

Is there any other solution?

Community
  • 1
  • 1
Koziołek
  • 2,791
  • 1
  • 28
  • 48
  • 1
    Post more of your code than this one statement. On one can tell what you've done from this line. – duffymo Apr 06 '11 at 11:37
  • 2
    typo in code or in post: `prepareStatement("Instert` - should be `Insert` – Andreas Dolk Apr 06 '11 at 11:39
  • That bug is for 7 or more parameters. You have 2. – jzd Apr 06 '11 at 11:42
  • @Andreas_D, done, @jzd nope because i get it when i have <7 params and use Statement.RETURN_GENERATED_KEYS. – Koziołek Apr 06 '11 at 11:45
  • 1
    @Koziolek, I believe you get the same error message, but unless the description of the bug is wrong in the link you are don't meet the criteria for "that" bug. – jzd Apr 06 '11 at 11:50
  • @jzd, hm... yes. This bug should call "(7 or more parameters) or (you want use Statement.RETURN_GENERATED_KEYS)"... ok. this is answer. – Koziołek Apr 06 '11 at 12:06

3 Answers3

2

Ok at this time we make workarount:

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

    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).

Koziołek
  • 2,791
  • 1
  • 28
  • 48
-1

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

CMP
  • 435
  • 3
  • 8
  • 22
-3

Please use ojdbc6.jar (rather than ojdbc6_g.jar) from oracle. It will solve this problem.

zaka
  • 1