Skip site navigation (1) Skip section navigation (2)

JDBC Latin1 problem

From: "J(dot) Michael Crawford" <jmichael(at)gwi(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: JDBC Latin1 problem
Date: 2004-08-04 18:34:39
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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:


   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=" +;  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

Next:From: Kris JurkaDate: 2004-08-04 18:47:22
Subject: Re: postgres and Jdbc 2.0
Previous:From: Dave CramerDate: 2004-08-04 14:43:30
Subject: Re: postgres and Jdbc 2.0

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group