setAsciiStream With Non-ASCII Characters Fails With ArrayIndexOutOfBoundException In executeUpdate (Doc ID 369798.1)

Last updated on AUGUST 03, 2016

Applies to:

JDBC - Version: 10.1
This problem can occur on any platform.

Symptoms

When using PreparedStatement.setAsciiStream to bind a byte array >4096 bytes to a CLOB column,

StringBuffer longString = new StringBuffer (4096);
for (int i=0; i<5000; i++)
{
    longString.append ('Ü');
}
PreparedStatement prep = conn.prepareStatement ("insert into testclobs values ('test', ?)");
ByteArrayInputStream data = new ByteArrayInputStream((longString.toString()).getBytes());
prep.setAsciiStream(1, data, longString.length());
prep.executeUpdate();

the executeUpdate() operation fails with

java.lang.ArrayIndexOutOfBoundsException: 4096
  at oracle.sql.CharacterSet.convertJavaCharsToUTFBytes(CharacterSet.java:1254)
  at oracle.jdbc.driver.DBConversion.javaCharsToCHARBytes(DBConversion.java:736)
  [...]
  at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2916)
  at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2988)

when the byte array contains a non-ASCII value.

Cause

Sign In with your My Oracle Support account

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

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms