Scrollable Resultset Returns Truncated Data (Doc ID 730318.1)

Last updated on AUGUST 16, 2016

Applies to:

JDBC - Version 10.1.0.5 and later
Information in this document applies to any platform.
This problem can occur on any platform.

Symptoms

Suppose a table TEST including column SP defined as CHAR(10) and with the following value defined:
insert into test values ('ääääääääää');

In SQL*Plus, the value is correctly returned:
SQL> select sp from test;
SP
ääääääääää

SQL> select dump(sp,16) from test;
DUMP(SP,16)
Typ=96 Len=10: e4,e4,e4,e4,e4,e4,e4,e4,e4,e4



However, when executing the code copied below with JDBC Thin Driver 10.1.0.5, only the first 5
characters are returned:
SQL>SELECT SP FROM TEST
5
äääää


This reproduces on WE8BS2000 Charset database Oracle 9i. It also reproduce with a 10g Database on Windows XP and Database Charset EE8MSWIN1250.
This happens when using TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_INSENSITIVE.
If TYPE_FORWARD_ONLY used then everything works.

Java code:

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

class hille {
  public static void main(String[] args) {
    try {
      String driverName = "oracle.jdbc.driver.OracleDriver";
      String url = "jdbc:oracle:thin:@host:port:sid";
      String user = "scott";
      String password = "tiger";
      //
      Class.forName(driverName);
      Connection connection = DriverManager.getConnection(url, user, password);
      DatabaseMetaData metaData = connection.getMetaData();
      String driverVersion = metaData.getDriverVersion();
      String driverName2 = metaData.getDriverName();
      System.out.println(driverVersion);
      System.out.println(driverName2);

      String sql = "SELECT SP FROM TEST";
      long lTime = System.currentTimeMillis();
      Statement statement = connection.createStatement();
      //
      System.out.println(sql);

      PreparedStatement ps =
        connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      ResultSet set = ps.executeQuery();

      if (! set.isBeforeFirst())
      {
        // Place the cursor right before the first row
        System.out.println("cursor gesetzt!");
        set.beforeFirst ();
      }
      set.beforeFirst ();

      while (set.next()) {
        System.out.println(set.getString(1).trim().length());
        System.out.println(set.getString(1));
      }
      set.close();
      statement.close();
      lTime = System.currentTimeMillis() - lTime;
      System.out.println("OracleTest.main()" + lTime);
      connection.close();
      //
      System.exit(0);
      //
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.exit(0);
  }
}



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