JDBC Latin1 problem - Mailing list pgsql-jdbc

From J. Michael Crawford
Subject JDBC Latin1 problem
Date
Msg-id 6.1.1.1.2.20040804140140.0337bf10@mail.nuomo.com
Whole thread Raw
Responses Re: JDBC Latin1 problem
List pgsql-jdbc

   We have a PostgreSQL 7.3.4 database running in redhat, defined as Latin1
when created, with the client connection sent to Latin1.  The data looks
fine when queried.  When using our server application running in windows
(jvm build 1.4.2_04-b05), with the pg73jdbc3.jar jdbc driver, we get the
right information from the rs.getString() method, and it looks fine in web
pages encoded with Latin1.

   However, when using the exact same classes and driver on the redhat
Linux box (jvm build 1.4.2_01-b06), we get garbage wherever there's a latin
character.  Same database, same classes, same driver.

   The Linux jvm has a default character encoding of UTF8, while the
windows jvm has a default character encoding of Cp1252.

   Here's what we've tried:


?charSet=

   We've tried every combination of adding ?charSet= to the url, such as
?charSet=LATIN1, ?charSet=ISO_8859_1, ?charSet=UTF_8, ?charSet=UNICODE, and
even appending the following to the url: "?charset=" +
sun.io.ByteToCharConverter.getDefault().getCharacterEncoding();  We've
tried both dashes and underscores.  We've also tried ?encoding= as well.


data = resultSet.getString("page_title_es");
byte[] text=data.getBytes("utf-8");
String data1=new String(text,"LATIN1");

   We've tried the above going from utf-8 to Latin1, utf-8 to utf-8, utf-8
to iso-8859-1, iso-8859-1 to utf-8, iso-8859-1 to Latin1, iso-8859-1 to
iso-8859-1, Latin1 to Latin1, Latin1 to utf-8, Latin1 to iso-8859-1.  We
may have tried others.  Nothing has helped.  We'll try nine at a time and
all will come up with some variation of "Introducción"  instead of
"Introducción" (hopefully this message shows the second introduccion with
an accent over the o, and not gibberish).


   Any ideas?  There's probably something very simple that will look
obvious in hindsight -- I'm sure that others have retrieved Latin1
characters from a Latin1 database via jdbc on a Linux jvm with a default
character set of utf-8.  I'm just not sure we'll be able to figure this one
out on our own.


    - Mike







pgsql-jdbc by date:

Previous
From: "Mike Martin"
Date:
Subject: Re: Wrong column names in ResultSetMetaData
Next
From: smota
Date:
Subject: Re: JDBC Latin1 problem