Subject Re: Fwd: FireBird JCA-JDBC driver character encoding bug [redcat@chnu.cv.ua]
Author rrokytskyy
Hi,

Yes, this is a bug. :( But I'm not sure if it will be easy to correct.
It happens only if a national characters are hardcoded in the SQL
statement itself:

PreparedStatement stmt = con.prepareStatement(
"INSERT INTO a_table VALUES('my national string', ?)");

If passed as parameter into PreparedStatement using setString(int,
String), everything will be ok. It also affects Statement instances.

I will check it, it seems to be easy to correct by checking value of
lc_ctype in DPB. But I'm not sure if we have access to DPB in the
places where XdrOutputStream is used.

Best regards,
Roman

--- In Firebird-Java@y..., David Jencks <davidjencks@d...> wrote:
> Roman and the other character set gurus, do you know anything about
this?
>
> thanks
>
> david jencks
>
> On 2002.08.20 11:13:07 -0400 RedCat wrote:
> Hello, David
>
> I use jca-jdbc driver in my projects. Nice thing, but I step in a
bug with
> encodings (Cp1251 in my case).
> The bug is: driver depends on operating system locale.
> I've look in sources, and I think that problem is in
> org.firebirdsql.jgds.XdrOutputStream class in this fragment:
>
> public final void writeString(String s) throws IOException {
> byte[] buffer = s.getBytes();
>
> This will convert String into byte array with default system
encoding, but
> the requied encoding may be different, as in my case (my Linux uses
KOI8-U,
> but database use WIN1251).
>
> When I change source and recompile driver, all was fine:
>
> public final void writeString(String s) throws IOException {
> byte[] buffer = s.getBytes("Cp1251");
>
> I hope, this will be corrected in release or next beta of jca-jdbc
driver.
>
> Please sorry for my terrible English (my lang. is Russian:).
>
> Good bye.
>
> Andrew Andrichenko
> redcat@c...
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META http-equiv=Content-Type content="text/html; charset=koi8-r">
> <META content="MSHTML 6.00.2600.0" name=GENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=#ffffff>
> <DIV><FONT face=Arial size=2>Hello, David</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>I use jca-jdbc driver in my projects. Nice
> thing,
> but I step in a bug with encodings (Cp1251 in my case).</FONT></DIV>
> <DIV><FONT face=Arial size=2>The bug is: driver depends on operating
system
>
> locale.</FONT></DIV>
> <DIV><FONT face=Arial size=2>I've look in sources, and I think that
problem
> is
> in org.firebirdsql.jgds.XdrOutputStream class in this
> fragment:</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>    public final void
> writeString(String s) throws IOException {</FONT></DIV>
> <DIV><FONT face=Arial size=2>       
> byte[]
> buffer = <STRONG>s.getBytes()</STRONG>; </FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>This will convert String into byte
array with
> default system encoding, but the requied encoding may be different,
as in
> my
> case (my Linux uses KOI8-U, but database use WIN1251).</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>When I change source and recompile
driver, all
> was
> fine:</DIV>
> <DIV> </DIV>
> <DIV>
> <DIV><FONT face=Arial size=2>    public final void
> writeString(String s) throws IOException {</FONT></DIV>
> <DIV><FONT face=Arial size=2>       
> byte[]
> buffer = <STRONG>s.getBytes("Cp1251")</STRONG>; </FONT></DIV>
> <DIV> </DIV>
> <DIV>I hope, this will be corrected in release or next beta of jca-jdbc
> driver.</DIV>
> <DIV> </DIV>
> <DIV>Please sorry for my terrible English (my lang. is Russian:).</DIV>
> <DIV> </DIV>
> <DIV>Good bye.</DIV>
> <DIV> </DIV>
> <DIV align=right>Andrew Andrichenko</DIV>
> <DIV align=right><A
>
href="mailto:redcat@c...">redcat@c...</A></DIV><BR></DIV></FONT></BODY></HTML>