Encoding issue (utf8): different strings received from java than from PGAdmin - Mailing list pgsql-jdbc

From Marc Mamin
Subject Encoding issue (utf8): different strings received from java than from PGAdmin
Date
Msg-id CA896D7906BF224F8A6D74A1B7E54AB301750A1E@JENMAIL01.ad.intershop.net
Whole thread Raw
List 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

pgsql-jdbc by date:

Previous
From: "ste.buffaishere@tin.it"
Date:
Subject: Prepared statement parameter and timestamp
Next
From: "Albe Laurenz"
Date:
Subject: Re: Encoding issue (utf8): different strings received from java than from PGAdmin