pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
 Reading £ character from DB is displaying œ character
11+ messages / 4 participants
[nested] [flat]

*  Reading £ character from DB is displaying œ character
@ 2013-09-22 04:53 saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  0 siblings, 1 reply; 11+ messages in thread

From: saisantoshi @ 2013-09-22 04:53 UTC (permalink / raw)
  To: pgsql-jdbc

Hi Everyone,

I am trying to read to read a foreign character from database (Get *£*100)
is giving some other character. I am using plain Java- JDBC connection. Just
wondering if there is anything that needs to be done apart from the below?

Below is the pseudo code:

connection = DriverManager.getConnection(
				
"jdbc:postgresql://127.0.0.1:5432/demodb?useUnicode=yes&characterEncoding=utf-8",
"test",
					"test");

String sql = "select * from test_data";
ResultSet rs = stmt.executeQuery(sql);
			while(rs.next()){

System.out.println(rs.getString(1))  // Returns Get *œ*100

Expected : Get *£*100)

}

DB is UTF-8
Postgres jar version : postgresql-9.0-801.jdbc4.jar

Appreciate if you could let me know if I am missing anything here?

Thanks,
Sai.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897....
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

*  RE: [JDBC] Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
@ 2013-09-23 17:04 ` Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Jim Garrison @ 2013-09-23 17:04 UTC (permalink / raw)
  To: pgsql-jdbc

> -----Original Message-----
> I am trying to read to read a foreign character from database (Get *£*100) is
> giving some other character. I am using plain Java- JDBC connection. Just
> wondering if there is anything that needs to be done apart from the below?
> 
> Below is the pseudo code:
> 
> connection = DriverManager.getConnection(
> 
> "jdbc:postgresql://127.0.0.1:5432/demodb?useUnicode=yes&characterEnco
> ding=utf-8",
> "test",
> 					"test");
> 
> String sql = "select * from test_data";
> ResultSet rs = stmt.executeQuery(sql);
> 			while(rs.next()){
> 
> System.out.println(rs.getString(1))  // Returns Get *œ*100

What is the OS? What software is *displaying* the output? Is it an IDE? A terminal? If the terminal isn't UTF-8 capable, or there's some output encoding going on you could have perfectly valid data in the resultset and see it corrupted on output to the console.

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* RE:  Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
@ 2013-09-23 18:33   ` saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  0 siblings, 1 reply; 11+ messages in thread

From: saisantoshi @ 2013-09-23 18:33 UTC (permalink / raw)
  To: pgsql-jdbc

OS where database is installed is Linux
OS where the java program is trying to read is Windows7
Using Eclipse IDE

Not sure if there is a problem with the Postgres JDBC driver or
ResultSet.getString() not reading it correctly from the DB.

Thanks,
Sai



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
@ 2013-09-23 20:32     ` saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  0 siblings, 1 reply; 11+ messages in thread

From: saisantoshi @ 2013-09-23 20:32 UTC (permalink / raw)
  To: pgsql-jdbc

client_encoding is set to "WIN1252"

I am try to set to UTF8, Trying to set a £ character in the update statement
is causing "invalid byte code sequence : 0x9x?"

Additional information:

server_encoding set to "UTF-8" as well.

If I set the client_encoding to WIN1252, it saves £ character correctly into
the database but the retrieval is a problem ( retrieves œ character)

Thanks,
Sai. 



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
@ 2013-09-23 20:58       ` saisantoshi <mr@starsborn.com>
  2013-09-23 23:02         ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  0 siblings, 1 reply; 11+ messages in thread

From: saisantoshi @ 2013-09-23 20:58 UTC (permalink / raw)
  To: pgsql-jdbc

Here is the exact error when trying to set to UT8 and updating £  character.

ERROR:  invalid byte sequence for encoding "UTF8": 0x9c



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
@ 2013-09-23 23:02         ` John R Pierce <pierce@hogranch.com>
  2013-09-24 00:27           ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  0 siblings, 1 reply; 11+ messages in thread

From: John R Pierce @ 2013-09-23 23:02 UTC (permalink / raw)
  To: pgsql-jdbc

On 9/23/2013 1:58 PM, saisantoshi wrote:
> Here is the exact error when trying to set to UT8 and updating £  character.
>
> ERROR:  invalid byte sequence for encoding "UTF8": 0x9c

WIn1252 is a Windows-specific variant of LATIN-1, an 8 bit character set.

0x9C is in fact the oe munged character in Win1252, and is an invalid 
character encoding in UTF8.

the UK pound symbol is 0xA3 in Win1252, and in UTF8, a UK pound sign 
is:  C2 A3, which is U+00A3 in UTF16/UCS2.

Win1252 code table:
http://en.wikipedia.org/wiki/Windows-1252#Code_page_layout

partial UTF8 char table:
http://www.utf8-chartable.de/


ahhhh.    0x9C is the pound symbol in CP437, the MSDOS CGA/EGA/VGA 
text-mode font.



-- 
john r pierce                                      37N 122W
somewhere on the middle of the left coast



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 23:02         ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
@ 2013-09-24 00:27           ` saisantoshi <mr@starsborn.com>
  2013-09-24 03:06             ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  0 siblings, 1 reply; 11+ messages in thread

From: saisantoshi @ 2013-09-24 00:27 UTC (permalink / raw)
  To: pgsql-jdbc

OK... I tried saving the  £ symbol into DB via java program as supposed to
psql command line and it works fine in saving/retreiving from DB ( via java
program)

But the issue here is, when I run the sql commands, it does not show me the 
£ symbol in the returned query.. (some gibberish character) May be because
DOS prompt default CP is 437. Not sure what do I need to do in order to see
the  £  symbol in the returned result set in running the queries or vewing
the data in the database.

testdb=> show server_encoding;
 server_encoding
-----------------
 UTF8
(1 row)

testdb=> set client_encoding = 'UTF8';
SET

testdb=> \encoding
UTF8

Select text from test;

*Get £500*   // Actual    ( Expected *Get £500* ) 


Not sure what the client_encoding and server_encoding does here?

Thanks,
Sai



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 23:02         ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  2013-09-24 00:27           ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
@ 2013-09-24 03:06             ` John R Pierce <pierce@hogranch.com>
  2013-09-24 04:52               ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  0 siblings, 1 reply; 11+ messages in thread

From: John R Pierce @ 2013-09-24 03:06 UTC (permalink / raw)
  To: pgsql-jdbc

On 9/23/2013 5:27 PM, saisantoshi wrote:
> Not sure what the client_encoding and server_encoding does here?

the server encoding gives the character encoding that the data is stored 
in.  the client encoding specifies the encoding used for user 
input/output, so user data in SQL commands will be converted from 
client_encoding to server_encoding when its written, and coverted back 
to the current client_encoding when read.

if you're running psql in a windows command shell, try setting the 
client_encoding to DOS437 or CP437 (I'm not sure what the correct 
notation is for this) and do your SELECT ...

Java itself uses UCS2/UTF16 internally, so I don't know what the right 
way of displaying text from a java program, it proably depends on 
whether you're displaying it on a text mode "DOS" window, or in a GUI 
window, or on a html page.




-- 
john r pierce                                      37N 122W
somewhere on the middle of the left coast



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 23:02         ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  2013-09-24 00:27           ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-24 03:06             ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
@ 2013-09-24 04:52               ` saisantoshi <mr@starsborn.com>
  2013-09-24 16:05                 `  RE: [JDBC] Re: Reading £ character from DB is displaying œ character Hudson, Derrick <dhudson@redcom.com>
  0 siblings, 1 reply; 11+ messages in thread

From: saisantoshi @ 2013-09-24 04:52 UTC (permalink / raw)
  To: pgsql-jdbc

Here is what I get:

testdb=> set client_encoding='DOS437';
ERROR:  invalid value for parameter "client_encoding": "DOS437"
testdb=> set client_encoding='CP437';
ERROR:  invalid value for parameter "client_encoding": "CP437"

The other question I have is if I am setting the
server_encoding/client_encodng to UTF8, then saving the £ character into DB
should save £ and be able to see the same in the table. I am still not clear
as to why it gets gibbersh characters... its much confusing as to believe if
it saved the right characters. Not sure what's missing peice here??





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

*  RE: [JDBC] Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 23:02         ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  2013-09-24 00:27           ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-24 03:06             ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  2013-09-24 04:52               ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
@ 2013-09-24 16:05                 ` Hudson, Derrick <dhudson@redcom.com>
  2013-09-25 02:55                   ` RE:  Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Hudson, Derrick @ 2013-09-24 16:05 UTC (permalink / raw)
  To: 'saisantoshi' <mr@starsborn.com>; pgsql-jdbc


How do you determine that you "get gibberish characters"?  Are you printing the string, or inspecting the individual characters in memory using a debugger?  The gibberish is probably the result of the way the text is displayed, not a problem with the database or the JDBC.  You need to correctly encode the string as bytes before sending it to System.out.  "correctly" depends on the encoding expected by your terminal (cmd.exe, the console of an IDE, etc.).

This answer on StackOverflow should be helpful;  it is equally applicable to the original question of JSON as it is to your question of JDBC.

http://stackoverflow.com/questions/11868022/unicode-characters-appearing-as-question-marks-in-java-j...




-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of saisantoshi
Sent: Tuesday, September 24, 2013 12:52 AM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] Re: Reading £ character from DB is displaying œ character

Here is what I get:

testdb=> set client_encoding='DOS437';
ERROR:  invalid value for parameter "client_encoding": "DOS437"
testdb=> set client_encoding='CP437';
ERROR:  invalid value for parameter "client_encoding": "CP437"

The other question I have is if I am setting the server_encoding/client_encodng to UTF8, then saving the £ character into DB should save £ and be able to see the same in the table. I am still not clear as to why it gets gibbersh characters... its much confusing as to believe if it saved the right characters. Not sure what's missing peice here??




-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* RE:  Re: Reading £ character from DB is displaying œ character
  2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 17:04 `  RE: [JDBC] Reading £ character from DB is displaying œ character Jim Garrison <jim.garrison@nwea.org>
  2013-09-23 18:33   ` RE:  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:32     ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 20:58       ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-23 23:02         ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  2013-09-24 00:27           ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-24 03:06             ` Re: Re: Reading £ character from DB is displaying œ character John R Pierce <pierce@hogranch.com>
  2013-09-24 04:52               ` Re: Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
  2013-09-24 16:05                 `  RE: [JDBC] Re: Reading £ character from DB is displaying œ character Hudson, Derrick <dhudson@redcom.com>
@ 2013-09-25 02:55                   ` saisantoshi <mr@starsborn.com>
  0 siblings, 0 replies; 11+ messages in thread

From: saisantoshi @ 2013-09-25 02:55 UTC (permalink / raw)
  To: pgsql-jdbc

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.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reading-character-from-DB-is-displaying-character-tp5771897p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2013-09-25 02:55 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-22 04:53  Reading £ character from DB is displaying œ character saisantoshi <mr@starsborn.com>
2013-09-23 17:04 ` Jim Garrison <jim.garrison@nwea.org>
2013-09-23 18:33   ` saisantoshi <mr@starsborn.com>
2013-09-23 20:32     ` saisantoshi <mr@starsborn.com>
2013-09-23 20:58       ` saisantoshi <mr@starsborn.com>
2013-09-23 23:02         ` John R Pierce <pierce@hogranch.com>
2013-09-24 00:27           ` saisantoshi <mr@starsborn.com>
2013-09-24 03:06             ` John R Pierce <pierce@hogranch.com>
2013-09-24 04:52               ` saisantoshi <mr@starsborn.com>
2013-09-24 16:05                 ` Hudson, Derrick <dhudson@redcom.com>
2013-09-25 02:55                   ` saisantoshi <mr@starsborn.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox