Sun's JDBC-ODBC bridge does not retrieve LONG VARCHAR column values
correctly. The bridge is inserting null characters before each of the
characters in the column's actual value. This symptom is seen with any
column whose width (or potential width) is greater than 32767, or if you
call ResultSet.getCharacterSteam() regardless of the column's width. Our
testing was done using the bridge that ships with JRE 1.3 with Sybase
Adaptive Server Anywhere 7.0.1 for the database.
I downloaded the source code for the JDBC-ODBC bridge, and I believe I
understand the source of this incorrect behavior. The JdbcOdbcInputStream
contains code to optionally inject null characters into the stream if the
"streamType" parameter to its constructor is ASCII or UNICODE. The null
characters are injected as data is read from the stream (see the "readData"
function and its call to "convertData").
I claim that this "conversion" is inappropriate in a Java Stream object
since streams are byte-oriented, not character-oriented. It's the job of a
java.io.Reader to convert the byte stream into a character stream.
To test this hypothesis, I removed the code that performs the conversion in
JdbcOdbcInputStream and recompiled the class. I then put the single class
file into a JAR, then ran a test program with the JAR in the boot class
path. The test program executes a SQL SELECT statement on a table with a
LONG VARCHAR column, then retrieves its value. The text was returned
correctly (i.e. no spurious blanks).
As an aside: This problem is new to JRE 1.3. The bridge that was shipped
with JRE 1.2.2 behaves properly.