Thread: character sets and results

character sets and results

From
Graham Leggett
Date:
Hi all,

I have been asked to fix a piece of code that submits queries to a
database, and returns string data that could possibly contain characters
with accents.

When the code returns the data (using standard SQL select statements)
the accented characters are replaced with a "?" character.

I have some other code which works correctly using the same select
statements, however in the other code a third party class is being used
to handle the database connections - I assume therefore that the
character sets being used are somehow specified on connection.

I have been trawling the postgresql-jdbc docs some for dome kind of
explanation on how to correctly handle different character sets, however
I have had no luck. Can anyone shed some light? Am I looking in the
right place?

Regards,
Graham
--
-----------------------------------------
minfrin@sharp.fm        "There's a moon
                    over Bourbon Street
                        tonight..."

Attachment

Re: character sets and results

From
Alaric B Snell
Date:
On Thursday 14 March 2002 10:41, Graham Leggett wrote:
> When the code returns the data (using standard SQL select statements)
> the accented characters are replaced with a "?" character.

I've found that if you create the database with UNICODE encoding, JDBC 'just
works' with respect to accented chars - I presume this is thanks to Java
natively using UTF-8 for strings!

I've not tried this with any characters beyond the range of Latin1, though.

ABS

--
Alaric B. Snell, Technical
abs@frontwire.com

Re: character sets and results

From
Graham Leggett
Date:
Alaric B Snell wrote:

> I've found that if you create the database with UNICODE encoding, JDBC 'just
> works' with respect to accented chars - I presume this is thanks to Java
> natively using UTF-8 for strings!
>
> I've not tried this with any characters beyond the range of Latin1, though.

Trouble is the two pieces of code both access the same database - but
one works, and the other doesn't. I cannot seem to figure out why, apart
from the odd connection broker (for which I have no source) used in the
code that works. This is why I assume there is some method during
connection to set the character set - but I cannot find it in the docs.

Regards,
Graham
--
-----------------------------------------
minfrin@sharp.fm        "There's a moon
                    over Bourbon Street
                        tonight..."

Attachment

Re: character sets and results

From
"Joe Shevland"
Date:
Do you have the non-working code handy? I was thinking the code might be doing some unnecessary conversion of the
Unicodestring that gets returned e.g. 

String foo = rs.getString("foo");
String bar = new String(foo.getBytes("US-ASCII"));

might cause something similar. As Alaric mentioned, if you use Unicode as the database character set, you shouldn't
haveto worry about any of these issues. Last CJK application I wrote, the biggest issue was character data from/to the
browser,is there any browser interaction or form postings going on? 

Cheers,
Joe

> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Graham Leggett
> Sent: Thursday, 14 March 2002 21:42
> To: Postgresql JDBC
> Subject: [JDBC] character sets and results
>
>
> Hi all,
>
> I have been asked to fix a piece of code that submits queries to a
> database, and returns string data that could possibly contain characters
> with accents.
>
> When the code returns the data (using standard SQL select statements)
> the accented characters are replaced with a "?" character.
>
> I have some other code which works correctly using the same select
> statements, however in the other code a third party class is being used
> to handle the database connections - I assume therefore that the
> character sets being used are somehow specified on connection.
>
> I have been trawling the postgresql-jdbc docs some for dome kind of
> explanation on how to correctly handle different character sets, however
> I have had no luck. Can anyone shed some light? Am I looking in the
> right place?
>
> Regards,
> Graham
> --
> -----------------------------------------
> minfrin@sharp.fm        "There's a moon
>                     over Bourbon Street
>                         tonight..."