Re: JDBC and Unicode problem

Поиск
Список
Период
Сортировка
От Zeljko Trogrlic
Тема Re: JDBC and Unicode problem
Дата
Msg-id 4.1.20000905201135.01494808@pop.tel.hr
обсуждение исходный текст
Ответ на JDBC and Unicode problem  (Zeljko Trogrlic <zeljko@technologist.com>)
Ответы Re: JDBC and Unicode problem  (Zeljko Trogrlic <zeljko@technologist.com>)
Список pgsql-interfaces
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 по дате отправления:

Предыдущее
От: Peter Mount
Дата:
Сообщение: RE: using large objects with jdbc
Следующее
От: Tom Samplonius
Дата:
Сообщение: ODBC (Windows) defaults to Read-Only?