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

Re: Encoding weirdness with JDBC, driver crashing?

From: Barry Lind <barry(at)xythos(dot)com>
To: Nikola Milutinovic <Nikola(dot)Milutinovic(at)ev(dot)co(dot)yu>
Cc: PostgreSQL JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Encoding weirdness with JDBC, driver crashing?
Date: 2001-11-06 02:58:04
Message-ID: 3BE751BC.9090907@xythos.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Nikola,

You shouldn't need to pass any encoding and you certainly shouldn't pass 
an encoding that is different than the database encoding.

If the database is created with LATIN2 (verify by 'select 
getdatabaseencoding()' from psql) then the jdbc driver will 
automatically convert from/to the database encoding to/from the unicode 
internal representation java uses.

If you explicitly set an encoding different than the database is using 
you will likely have problems since then the driver will convert from/to 
this encoding instead of the encoding the database is using.

If you are still having problems, please post a simple test case that I 
can run locally to reproduce your problem

thanks,
--Barry



Nikola Milutinovic wrote:

> Hi all.
> 
> I'm having a weird episode with JDBC connection and charSet encoding.
> 
> OS: Digital UNIX 4.0D/F
> DB: PostgreSQL 7.1.2 and 7.1.3
> 
> I have created a database with "-E LATIN2" option. Then I imported a 
> WIN1250 encoded data into it - the data was generated from a set of 
> static HTML pages and loading was with WIN1250 client encoding.
> 
> The data looks OK from "psql", changing client encoding yields the 
> expected result. I'm preety sure it is as it should be.
> 
> JDBC interface behaves in a very weird manner:
> 
> URL: jdbc:postgresql://localhost/mercury
> OUT: all our alphabet specific characters are tuned into "?"
> 
> URL: jdbc:postgresql://localhost/mercury?charSet=LATIN1
> OUT: I get data OK - LATIN2 encoded!!!
> 
> URL: jdbc:postgresql://localhost/mercury?charSet=LATIN2
> OUT: all our alphabet specific characters are tuned into "?"
> 
> URL: jdbc:postgresql://localhost/mercury?charSet=UNICODE
> OUT: JDBC connection crashes with:
> 
> Exception in thread "main" java.sql.SQLException:
>  at org.postgresql.Connection.ExecSQL(Connection.java, Compiled Code)
>  at org.postgresql.jdbc2.Statement.execute(Statement.java, Compiled Code)
>  at org.postgresql.jdbc2.Statement.executeQuery(Statement.java, Compiled 
> Code)
>  at test2PostgreSQL.main(test2PostgreSQL.java, Compiled Code)
> 
> On the server side, PostgreSQL spits out:
> 
> ERROR:  parser: parse error at or near "t?"
> FATAL 1:  Socket command type S unknown
> 
> (on my terminal, that "t?" looks really strange, two chars I cannot even 
> describe, I guess Copy/Paste changed it to "t?")
> 
> So, anyone has an idea what is going on? I can live with 
> "charSet=LATIN1" for the moment, but I have a nasty feeling, the data is 
> not loaded as it should be. Namely, I'm not sure that, for instance, 
> "c-acsan" letter Latin-2 encoded in PostgreSQL is really transformed 
> into "c-acsan" Unicode encoded inside my Java application.
> 
> Since I'm more oriented to JSP for this matter, I'll live with it, but I 
> have an uneasy feeling about it. I think this issue should be addressed.
> 
> PostgreSQL was built with:
> 
> --enable-locale              enable locale support
> --enable-recode              enable character set recode support
> --enable-multibyte           enable multibyte character support
> --enable-unicode-conversion  enable unicode conversion support
> 
> TYIA,
> Nix.
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
> 



In response to

Responses

pgsql-jdbc by date

Next:From: Barry LindDate: 2001-11-06 03:11:38
Subject: Re: Backend Protocol
Previous:From: Carlos AugustoDate: 2001-11-06 02:04:40
Subject: Re:

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