My Oracle Support Banner

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

Last updated on MARCH 08, 2017

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:


package test.oracle;

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 TEST_TABLE (
F_ID NUMBER(38) not null,
F_1 VARCHAR2(50) default 'default' not null,
F_2 VARCHAR2(50) default 'default' not null,
F_3 VARCHAR2(50) default 'default' not null,
F_4 VARCHAR2(50) default 'default' not null,
F_5 VARCHAR2(50) default 'default' not null,
F_6 VARCHAR2(50) default 'default' not null,
F_7 VARCHAR2(50) default 'default' not null,
F_8 VARCHAR2(50) default 'default' not null,
F_9 VARCHAR2(50) default 'default' not null,
F_10 VARCHAR2(50) default 'default' not null,
CONSTRAINT TEST_TABLE_PK PRIMARY KEY(F_ID)
);

CREATE SEQUENCE TEST_TABLE_SEQ START WITH 1 INCREMENT BY 1;

CREATE OR REPLACE TRIGGER TEST_TABLE_SEQ_TRG
BEFORE INSERT ON TEST_TABLE FOR EACH ROW
BEGIN
SELECT TEST_TABLE_SEQ.NEXTVAL INTO :NEW.F_ID FROM DUAL;
END;
/

*/
public class TestOraclePreparedStatement {

/**
* @param args -
*/
public static void main(final String[] args) {
try {
DriverManager.registerDriver(new OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:ESBIOBOX", "SYSTEM", "root");
PreparedStatement stmnt = conn.prepareStatement(
"INSERT INTO TEST_TABLE (F_1,F_2,F_3,F_4,F_5,F_6,F_7)"
+ " values (?,?,?,?,?,?,?)", new String[] { "F_ID" });
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 TEST_TABLE (F_1,F_2,F_3,F_4,F_5,F_6,F_7,F_8)"
+ " values (?,?,?,?,?,?,?,?)", new String[] { "F_ID" });
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)
at test.oracle.TestOraclePreparedStatement.main(TestOraclePreparedStatement.java:84)



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
Cause
Solution

This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.
My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.