Subject Re: [Firebird-Java] reading binary data (CHARACTER SET OCTETS)
Author Roman Rokytskyy
> Hi,
>
> I have problem with reading binary data defined as CHAR(n) CHARACTER SET
> OCTETS using JayBird (1.5.x, 2.x).
>
> The values are returned as String, so non-ascii characters are
> corrupted.

This is correct, since they are interpreted according to the connection
encoding (and if none is specified, it uses default encoding for JVM).

> I think that correct type of binary data should be byte[].

Depends. The CHAR/VARCHAR columns according to the JDBC specification are
by default mapped to String. That means that ResultSet.getObject(int) will
return you an instance of java.lang.String class. However, nobody prevents
you from using ResultSet.getBytes(int) method and you will get the raw
data.

> I'm using JayBird through 3rd party Java application Kettle
> (kettle.javaforge.com) which supports JDBC connections. With MySQL JDBC
> driver I have no problem, VARBINARY(n) column type is readed as byte[].

VARBINARY is not VARCHAR CHARACTER SET OCTESTS. And unfortunately Firebird
does not support VARBINARY type...

> The second question is: is there any way to read data defined as CHAR(n)
> CHARACTER SET NONE as binary data? I don't want JayBird or JVM to make
> any character conversions when reading/writting data.

Use the ResultSet.getBytes(int) method and ensure that you do not specify
connection charSet or encoding.

Roman