ResultSet.getbytes Using BLOB Returns Incorrect Data using 9.2 JDBC Driver (Doc ID 377265.1)

Last updated on AUGUST 03, 2016

Applies to:

JDBC
Information in this document applies to any platform.

Symptoms

Using the 9.2.0.X JDBC Driver, ResultSet.getBytes returns invalid data. For example:

Test results when run against the Oracle 9.2.0.x driver...

getBlobs() - bl_id = 1234, myobject.length=86 0, 84, 0, 1, 1, 12, 0,
0, 0, 1, , ... (Invalid data).


Test results when run against the Oracle 10g driver...

getBlobs() - bl_id = 1234, myobject.length=128 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, , ... (Valid data).


Here is the code that generates the above output:

        private static void getBlobs(Connection con) throws SQLException {
            PreparedStatement ps = con
                    .prepareStatement("SELECT bl_id, myobject FROM testblobs");
            ResultSet rs = ps.executeQuery();
   
            while (rs.next()) {
   
                int bl_id = rs.getInt("bl_id");
                byte[] myobject = rs.getBytes("myobject");
   
                System.out.println("getBlobs() - bl_id = " + bl_id
                        + ", myobject.length=" + myobject.length);
   
                for (int idx = 0; idx < myobject.length && idx < 10; idx++) {
                    System.out.print((int) myobject[idx] + ", ");
                }
                System.out.println(", ... "
                        + (myobject[0] == 10 && myobject[1] == 11 ? "(Valid data)."
                                : "(Invalid data)."));
            }
   
            rs.close();
            ps.close();
        }



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