RE: JDBC and Unicode problem
От | Peter Mount |
---|---|
Тема | RE: JDBC and Unicode problem |
Дата | |
Msg-id | 1B3D5E532D18D311861A00600865478CF1B350@exchange1.nt.maidstone.gov.uk обсуждение исходный текст |
Ответ на | JDBC and Unicode problem (Zeljko Trogrlic <zeljko@technologist.com>) |
Список | 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@maidstone.gov.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@technologist.com] Sent: Tuesday, September 05, 2000 7:47 PM To: pgsql-interfaces@postgresql.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.
В списке pgsql-interfaces по дате отправления: