X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7628B3A61E9 for ; Thu, 13 Jan 2005 23:36:38 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50476-03 for ; Thu, 13 Jan 2005 23:36:26 +0000 (GMT) Received: from mail.gmx.net (pop.gmx.net [213.165.64.20]) by svr1.postgresql.org (Postfix) with SMTP id EE6133A6475 for ; Thu, 13 Jan 2005 23:36:26 +0000 (GMT) Received: (qmail invoked by alias); 13 Jan 2005 23:36:25 -0000 Received: from pop-ls-6-2-dialup-60.freesurf.ch (EHLO [194.230.231.60]) (194.230.231.60) by mail.gmx.net (mp006) with SMTP; 14 Jan 2005 00:36:25 +0100 X-Authenticated: #9655330 Message-ID: <41E7059D.8040001@gmx.ch> Date: Fri, 14 Jan 2005 00:34:53 +0100 From: Jerome Colombie User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Jurka Cc: Oliver Jowett , pgsql-jdbc@postgresql.org Subject: Re: Encoding Problem References: <41E59519.7080807@gmx.ch> <41E59C1B.6050804@opencloud.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.171 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/106 X-Sequence-Number: 11986 Hi, I made a low-level program which prints to the console. It seems that the jdbc driver is correct, although the Strings need some postprocessing in Java. I want to create html output, so I don't know if I have to change my windows settings, java settings (Locale) or just need to reformat the strings in java code. My test program looks like this: ********* bh=# create table test ( t VARCHAR(5) ); bh=# insert into test values ('aäöü'); bh=# select * from test; t ------ aäöü (1 row) bh=# select getdatabaseencoding(); getdatabaseencoding --------------------- LATIN1 (1 row) bh=# SHOW client_encoding; client_encoding ----------------- LATIN1 (1 row) bh=# select version(); version -------------------------------------------------------------------------------------------------------- PostgreSQL 8.0.0rc2 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.3.1 (mingw special 20030804-1) (1 row) ********* import java.sql.*; import java.util.Properties; public class BaseDAO { protected static String dbHost = "localhost"; protected static String dbUrl = "jdbc:postgresql://" + dbHost + ":5432/bh"; protected static String dbUser = "postgres"; protected static String dbPassword = "***"; protected static String dbDriver = "org.postgresql.Driver"; static { //Register driver try { DriverManager.registerDriver((Driver)Class.forName(dbDriver).newInstance()); } catch (Exception e){ System.out.println("Error: " + e); } } public BaseDAO() { super(); try { Properties props = new Properties(); props.put("user", dbUser); props.put("password", dbPassword); Connection con = DriverManager.getConnection(dbUrl, props); ResultSet rs = con.createStatement().executeQuery("select * from test"); if (rs.next()) { byte[] temp = rs.getString("t").getBytes(); System.out.println("Database String"); System.out.println(rs.getString("t")); System.out.println("Database Bytes"); for (int i = 0; i < temp.length; i++) { System.out.println(temp[i]); } } } catch(SQLException se) { System.out.println("Error: " + se); } } public static void main(String[] args) { BaseDAO dao = new BaseDAO(); String test = "aäöü"; System.out.println("Java String"); System.out.println(test); System.out.println("Java Bytes"); byte[] temp = test.getBytes(); for (int i = 0; i < temp.length; i++) { System.out.println(temp[i]); } try { System.out.println("ISO-8859-1"); String t1 = new String("aäöü".getBytes(), "ISO-8859-1"); temp = t1.getBytes(); for (int i = 0; i < temp.length; i++) { System.out.println(temp[i]); } } catch (java.io.UnsupportedEncodingException e) { System.out.println("Encoding exception: " + e); } try { System.out.println("UTF-8"); String t1 = new String("aäöü".getBytes(), "UTF-8"); temp = t1.getBytes(); for (int i = 0; i < temp.length; i++) { System.out.println(temp[i]); } } catch (java.io.UnsupportedEncodingException e) { System.out.println("Encoding exception: " + e); } } } ********* D:\temp\test>javac BaseDAO.java D:\temp\test>java -classpath d:\projects\jar\pg74.214.jdbc3.jar;. BaseDAO Database String a??? Database Bytes 97 63 63 63 Java String aõ÷³ Java Bytes 97 -28 -10 -4 ISO-8859-1 97 -28 -10 -4 UTF-8 97 63 63 ********* How can I get the correct output in html with java code? I know that technically it hasn't got to do with jdbc but I still hope someone can give me a solution so I don't need to change the java code. I hope I can solve this problem by changing either the database configuration or the java or windows locale. Regards, Jerome