Encoding issue (utf8): different strings received from java than from PGAdmin

From: "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Encoding issue (utf8): different strings received from java than from PGAdmin
Date: 2007-04-05 14:48:41
Message-ID: CA896D7906BF224F8A6D74A1B7E54AB301750A1E@JENMAIL01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello,

I have a strange issue, probably with the jdbc client:

JDBC Version: postgresql-8.2-504
PG version: 8.2

The PG Database, the PG Client and java allworks in UTF8 context.

step to repeat:

1)

create this postgres function that just write the input parameter in /opt/<pgdata>/pg_log/:

CREATE OR REPLACE FUNCTION public.raisecode(v character varying)
RETURNS integer AS
$BODY$

BEGIN
RAISE WARNING 'raisecode output: %',v;
return 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

2) call "select raisecode('$§Kü§$')"
from a postgres client like PGAdmin

(also check the client encoding: select pg_client_encoding())

3) call the same statements from within a java application:

try {

conn.createStatement().execute("select raisecode(cast(pg_client_encoding() as varchar))");
conn.createStatement().execute("select raisecode('$§Kü§$')");

} catch (SQLException e) {
// TODO Auto-generated catch block
throw new ApplicationException("Could not select raisecode('$§Kü§$')",e);
}

compare the output in pg_log:

2 => $§Kü§$
3 => $çKüç$

note: in postgres client , you can also try this:
select convert ('§' using utf8_to_iso_8859_1) => §

When called from java, it seems that the character à is added before the special characters §(§) and ¼(ü)
This probably apply to all characters whose code is > 127...

Thanks for any hint,

Marc

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Albe Laurenz 2007-04-06 07:39:04 Re: Encoding issue (utf8): different strings received from java than from PGAdmin
Previous Message ste.buffaishere@tin.it 2007-04-03 09:28:29 Prepared statement parameter and timestamp