14

I'm getting an Exception while trying to insert a row in oracle table. I'm using ojdbc5.jar for oracle 11 this is the sql i'm trying

INSERT INTO rule_definitions(RULE_DEFINITION_SYS,rule_definition_type,
rule_name,rule_text,rule_comment,rule_message,rule_condition,rule_active,
rule_type,current_value,last_modified_by,last_modified_dttm,
rule_category_sys,recheck_unit,recheck_period,trackable)
VALUES(RULE_DEFINITIONS_SEQ.NEXTVAL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

and i get following Exception. Any help will be appreciated.

java.ljava.lang.ArrayIndexOutOfBoundsException: 15
at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java:950)
    at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java:623)
    at oracle.jdbc.driver.OraclePreparedStatement.(OraclePreparedStatement.java:1212)
    at oracle.jdbc.driver.T4CPreparedStatement.(T4CPreparedStatement.java:28)
    at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java:68)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3059)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:2961)
    at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5874)
    at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:232)
    at com.gehcit.platform.cds.common.util.db.DBWrapper.executeInsertOracleReturnPK(DBWrapper.java:605)
Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
lostinbytes
  • 293
  • 2
  • 3
  • 11

7 Answers7

27

In Oracle Metalink (Oracle's support site - Note ID 736273.1) I found that this is a bug in JDBC adapter (version 10.2.0.0.0 to 11.1.0.7.0) that when you call preparedStatement with more than 7 positional parameters then JDBC will throw this error.

If you have access to Oracle Metalink then one option is to go there and download mentioned patch.

The other solution is workaround - use named parameters instead of positional parameters:

INSERT INTO rule_definitions(RULE_DEFINITION_SYS,rule_definition_type,
rule_name,rule_text,rule_comment,rule_message,rule_condition,rule_active,
rule_type,current_value,last_modified_by,last_modified_dttm,
rule_category_sys,recheck_unit,recheck_period,trackable)
VALUES(RULE_DEFINITIONS_SEQ.NEXTVAL,:rule_definition_type,
:rule_name,:rule_text,:rule_comment,:rule_message,:rule_condition,:rule_active,
:rule_type,:current_value,:last_modified_by,:last_modified_dttm,
:rule_category_sys,:recheck_unit,:recheck_period,:trackable)

and then use

preparedStatement.setStringAtName("rule_definition_type", ...)

etc. to set named bind variables for this query.

Raimonds Simanovskis
  • 2,948
  • 1
  • 21
  • 17
  • 3
    It works fine unless generated keys are needed to be returned. At least I still get this error. I am using spring's template: KeyHolder keyHolder = new GeneratedKeyHolder(); SqlParameterSource paramSource = new BeanPropertySqlParameterSource(item); simpleJdbcTemplate.getNamedParameterJdbcOperations().update(sql, paramSource, keyHolder, new String[] { "id" }); Any ideas? – Anton Kuzmin Apr 20 '09 at 15:54
  • Metalink patch still does not fix the bug in some specific cases. For example this query does not work neither with patched ojdbc nor with most recent ojdbc version (11.2.0.1.0 ): select 1 from dual where 1 in (?,?,?,?,?,?,?,?) and 1=:foo However this query works just fine: select 1 from dual where 1 in (?,?,?,?,?,?,?) and 1=:foo Conclusion: don't mix positional and named parameters to avoid this particular problem. – Misha Oct 13 '09 at 10:28
  • @Raimonds Can you provide oracle metalink url from where i can download patch ? How to ues that patch? Is there another solution from mentioned above – Kamlesh Kanazariya Jan 22 '15 at 08:19
1

i am using mybatis + oracle + spring + maven. Same error "arrayindexoutofboundsexception", if having 8 (or) above parameters.

In pom changed version ojdbc6 to ojdbc14,

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.3.0</version>
    </dependency>

It worked.

Siva Anand
  • 2,872
  • 2
  • 18
  • 9
0

When you don't have access to the oracle.jdbc.PreparedStatement class (and are forced to use java.sql.PreparedStatement, which does not support the methods #setXXXAtName()), the proposed solution to use named parameters is not an option.

I've used the PreparedStatement and GeneratedKeyHolder approach for the mandatory values to be passed (luckily less than 7), and used the generated primary key returned to issue a simple SQL update for the remaining values.

Stephan
  • 41,764
  • 65
  • 238
  • 329
0

Without seeing the code, the only thing I can think of is to check that each connection is being accessed in a thread safe manner. The Oracle drivers are usually pretty solid. The only time I've seen weird internal errors like that is when you've got more than one thread accessing the same connection instance and doing weird stuff with it. They aren't thread safe, and should be kept to one per thread.

madlep
  • 47,370
  • 7
  • 42
  • 53
0

You create a prepared statement with 15 placeholders, if i understand correct. So you need to pass an array with 15 parameter values to the call. Maybe you missed one or added a surplus one?

Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94
0

Looks like you're passing in the wrong number of parameters. You should be passing in 15, but you're either sending 16 or 14.

Elie
  • 13,693
  • 23
  • 74
  • 128
0

Yeah unless my mouse-cursor-counting is off, you're trying to insert 16 values into 15 columns.

Try the same thing SQLPlus*, you should get ORA-00913: too many values

Colin Pickard
  • 45,724
  • 13
  • 98
  • 148