Re: [JDBC] Re: Reading £ character from DB is displaying œ character

Поиск
Список
Период
Сортировка
От Lachezar Dobrev
Тема Re: [JDBC] Re: Reading £ character from DB is displaying œ character
Дата
Msg-id CA+xsaB1t4QUKw_NJgnS-1UHvZEynRUFQv0bA3gJ-vJ0RjBB1Yw@mail.gmail.com
обсуждение исходный текст
Ответ на RE: Re: Reading £ character from DB is displaying œ character  (saisantoshi <mr@starsborn.com>)
Список pgsql-jdbc
  I have had problems of this sort while I was working under Windows.
  There are *numerous* places where character encoding needs to be
specified correctly. Java is UNICODE by default, so is PostgreSQL, and
correct character encoding is vital to making all the things work
together.
  The places where things can go wrong are:

  - Character encoding in the editor that is used to write the source code
  - Character encoding when compiling the code
  - Character encoding used when inserting in the database
(client-side encoding)
  - Character encoding used by the database (server-side)
  - Character encoding used when selecting from the database
(client-side encoding)
  - Character encoding used when outputting the content
  - Character encoding of the output media

  One _could_ mix and match different encodings at different steps,
but it's a process prone to errors. Using a single encoding everywhere
helps (although it can mask problems).

  I've had numerous occasions where colleagues would write code in
Windows, and saved the file with their local Code Page, which is *not*
UTF-8. The code was compiled on a system with UTF-8 as default
encoding, and the code ended up containing wrong literals. I've had
the opposite too: colleagues have compiled UTF-8 code on their
machines with a different local encoding, and got broken string
literals.

  It is also possible, that the console you're using (command prompt?)
uses one encoding, while your code that outputs the read data uses a
different one.

  Here's what I mean:

> C:\Program Files\PostgreSQL\9.3\bin>psql -h database lachezar lachezar
> Password for user lachezar:
> psql (9.3.0)
> WARNING: Console code page (866) differs from Windows code page (1251)
>         8-bit characters might not work correctly. See psql reference
>         page "Notes for Windows users" for details.
> Type "help" for help.
>
> lachezar=> select username, personal_name from users where username = 'lachezar';
>  username | personal_name
> ----------+----------------
>  lachezar | ╦·ўхчрЁ ─юсЁхт
> (1 row)
>
>
> lachezar=> \encoding WIN866
> lachezar=> select username, personal_name from users where username = 'lachezar';
>  username | personal_name
> ----------+----------------
>  lachezar | Лъчезар Добрев
> (1 row)

  Just because *you* can't see the correct content, it does not mean,
that it's the database's fault (and I'm pretty sure it is not).

  Check every one of the elements I noted above. It might be the
editor you're using! Using Notepad has yielded problems of that sort.
In all honesty I've resorted to decompiling code to *catch*
lazy/ignorant/newbie developers that fail to set up a development
environment correctly.

  Still... Make sure your database is actually capable of storing
those characters

> lachezar=> \l+ lachezar
>                                                 List of databases
>     Name  |  Owner   | Encoding |   Collate   |    Ctype    | Access privileges | Size  | Tablespace | Description
> ----------+----------+----------+-------------+-------------+-------------------+-------+------------+-------------
>  lachezar | lachezar | UTF8     | bg_BG.UTF-8 | bg_BG.UTF-8 |                   | 13 GB | pg_default |
> (1 row)

  Strictly speaking you might be able to put incompatible characters,
but that can yield unpredictable results.

2013/9/25 saisantoshi <mr@starsborn.com>:
> I understand that its not gibberish.. but the problem is how can I set the
> editor to view the right character set. I am using DOS propmt ( and
> connectng it to PSQL client) to view the data in DB. Now, there are
> different audience viewing the data set from DB. If the vewer can't
> determine what the character is.. it would be very annoying.. There should
> be a way in DOS prompt to set the terminal to view the data which is UTF-8.
> Not able to view the data is a limitation on Wndows OS.
>
> Thanks,
> Sai.


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Stephen Nelson
Дата:
Сообщение: Re: Maven repo version
Следующее
От: Lachezar Dobrev
Дата:
Сообщение: Re: Maven repo version