RE: JDBC and Unicode problem

From: Peter Mount <petermount(at)maidstone(dot)gov(dot)uk>
To: "'Zeljko Trogrlic'" <zeljko(at)technologist(dot)com>, pgsql-interfaces(at)postgresql(dot)org
Cc: "Peter Mount (Home)" <peter(at)retep(dot)org(dot)uk>
Subject: RE: JDBC and Unicode problem
Date: 2000-09-06 08:01:48
Message-ID: 1B3D5E532D18D311861A00600865478CF1B350@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

It isn't a bug as such as I've never implemented unicode.

However, your solution looks like a good one, but I'm not sure how you would
pass that parameter to either an applet or a servlet.

There's a lot of factors here, which cause JDBC to suffer. Because of the
sheer amount of email I see (about 200 a day each at work and at home), I
tend to read only emails that say "JDBC" in the subject line. However, this
means that a lot of the time I miss out on emails saying that something has
changed (eg: getTimestamp() fails due to the format changing slightly
between versions), and I know there's a lot of functionality in 7.0 that
would improve things but I haven't seen enough examples to actually
implement them...

Peter

--
Peter Mount
Enterprise Support Officer, Maidstone Borough Council
Email: petermount(at)maidstone(dot)gov(dot)uk
WWW: http://www.maidstone.gov.uk
All views expressed within this email are not the views of Maidstone Borough
Council

-----Original Message-----
From: Zeljko Trogrlic [mailto:zeljko(at)technologist(dot)com]
Sent: Tuesday, September 05, 2000 7:47 PM
To: pgsql-interfaces(at)postgresql(dot)org
Cc: Peter Mount
Subject: Re: [INTERFACES] JDBC and Unicode problem

After browsing through hundreds of messages, downloading source etc. I
finally found how to use UNICODE from JDBC. This is problem because of bug
in driver which I'll explain later. I'll post that here to help other with
the same problem:

Check that PostgreSQL supports UNICODE with SELECT getdatabaseencoding();
Check that database is created for UNICODE: open psql and type \l[ENTER]
Maybe you should do just one of above; I'm not sure.
Check that you have correct code page during compiling Java source, or your
String constants will be wrong. In JBuilder 3.0: Project -> Properties ->
Compiler -> Encoding

And now solution for JDBC problems:
Add to Java parameters -Dfile.encoding=UTF-8

Everything should work now, but mind that all methods that use default
encoding (file readers/writers, string.toBytes()) will use UTF-8 so you
have to explicitly say which encoding you use.

This is because of bug in driver; in connection.ExecSQL there is line
buf = sql.getBytes();
This line uses platform default encoding. If you use Cp1250, sql statement
will be encoded for that code page, or whatever code page you use, BUT IT
SHOULD BE ENCODED FOR DATABASE'S CODE PAGE!

The best solution will be if Connection reads which encoding PostgreSQL
expects and to replace line with:
buf = sql.getBytes(javaEncodingName);
(PostgreSQL's UNICODE must be converted to standard UTF-8)

Less perfect, but also acceptable solution will be to inform driver somehow
which encoding to use.

One of the options will be to use "SET client_encoding", but PostgreSQL
don't have support for Unicode-to-something-else support.

Solution is based on Tatsuo Ishii's postings.

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 2000-09-06 08:15:33 RE: Re: JDBC and java.sql.Timestamp
Previous Message Joachim Achtzehnter 2000-09-06 05:47:16 Re: JDBC Driver Help...