My Oracle Support Banner

Connection.Preparestatementgets ArrayIndexOutOfBoundsException When IN Parameters >7 (Doc ID 1226193.1)

Last updated on AUGUST 09, 2019

Applies to:

JDBC - Version 11.1.0.6 to 11.1.0.6 [Release 11.1]
Information in this document applies to any platform.

Symptoms


Using Jdbc driver 11.1.0.6.0 a problem with 'INSERT' type PreparedStatement creation when statement has generated keys array. When INSERT has 7 or less fields as values everything going well, but if INSERT is using 8 or more fields, method prepareStatement(String,String[]) throws exception. Here is java code:



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.OracleDriver;

/* SQL DDL SCRIPT for Oracle :
CREATE TABLE <TABLE_NAME> (
<COLUMN1> NUMBER(38) not null,
<COLUMN2> VARCHAR2(50) default 'default' not null,
<COLUMN3> VARCHAR2(50) default 'default' not null,
<COLUMN4> VARCHAR2(50) default 'default' not null,
<COLUMN5> VARCHAR2(50) default 'default' not null,
<COLUMN6> VARCHAR2(50) default 'default' not null,
<COLUMN7> VARCHAR2(50) default 'default' not null,
<COLUMN8> VARCHAR2(50) default 'default' not null,
<COLUMN9> VARCHAR2(50) default 'default' not null,
<COLUMN10> VARCHAR2(50) default 'default' not null,
<COLUMN11> VARCHAR2(50) default 'default' not null,
CONSTRAINT <TABLE_NAME>_PK PRIMARY KEY(<COLUMN1>)
);

CREATE SEQUENCE <TABLE_NAME>_SEQ START WITH 1 INCREMENT BY 1;

CREATE OR REPLACE TRIGGER <TABLE_NAME>_SEQ_TRG
BEFORE INSERT ON <TABLE_NAME> FOR EACH ROW
BEGIN
SELECT <TABLE_NAME>_SEQ.NEXTVAL INTO :NEW.<COLUMN1> FROM DUAL;
END;
/

*/
public class <CLASS NAME> {

/**
* @param args -
*/
public static void main(final String[] args) {
try {
DriverManager.registerDriver(new OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@<HOST>:<PORT>:<SID>", "<USER>", "<PASSWORD>");
PreparedStatement stmnt = conn.prepareStatement(
"INSERT INTO <TABLE_NAME> (<COLUMN2>,<COLUMN3>,<COLUMN4>,<COLUMN5>,<COLUMN6>,<COLUMN7>,<COLUMN8>)"
+ " values (?,?,?,?,?,?,?)", new String[] { "<COLUMN1>" });
int i = 1;
stmnt.setString(i++, "One");
stmnt.setString(i++, "Two");
stmnt.setString(i++, "Three");
stmnt.setString(i++, "Four");
stmnt.setString(i++, "Five");
stmnt.setString(i++, "Six");
stmnt.setString(i++, "Seven");
stmnt.execute();
ResultSet rs = stmnt.getGeneratedKeys();
rs.next();
System.out.println("7-field row id = " + rs.getLong(1));
rs.close();
stmnt.close();

stmnt = conn.prepareStatement(
"INSERT INTO <TABLE_NAME> (<COLUMN2>,<COLUMN3>,<COLUMN4>,<COLUMN5>,<COLUMN6>,<COLUMN7>,<COLUMN8>,<COLUMN9>)"
+ " values (?,?,?,?,?,?,?,?)", new String[] { "<COLUMN1>" });
i = 1;
stmnt.setString(i++, "One");
stmnt.setString(i++, "Two");
stmnt.setString(i++, "Three");
stmnt.setString(i++, "Four");
stmnt.setString(i++, "Five");
stmnt.setString(i++, "Six");
stmnt.setString(i++, "Seven");
stmnt.setString(i++, "Eight");
stmnt.execute();
rs = stmnt.getGeneratedKeys();
rs.next();
System.out.println("8-field row id = " + rs.getLong(1));
rs.close();
stmnt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

}



Output is:

7-field row id = 22
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
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:3059)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:2961)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5940)

 

Changes

 

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Symptoms
Changes
Cause
Solution
References

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.