Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unicode Charaters from a database

 
John Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to retrieve the unicode values of currency symbols from a database (we had lots of problems with locales so this is the way it's being done).
In the database, the unicode representations eg \u20ac have been defined as Varchar2 but when they get into the Java layer, they appear as "\\u20ac". I have tried returning just the 20ac part & appending "\u" to it but JBuilder complains about illegal unicode escape characters.
Anyone know how I can arrive at the equivalent of String x = "\u20ac" ??
Thanks
 
Eric McIntyre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're on the right track. I came up with this, but it's hard to verify in a DOS prompt:

Whaddaya think?
Eric
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason JBuilder complains is that "\u" indicates the start of an escape sequence. It expects the unicode value after the 'u', but doesn't see it. There is a way to fix this so it will compile, but I doubt it will do anygood. Instead, I have a few questions:

1) Does your database support Unicode characters in a column with type VARCHAR?

2) If so, why don't you just store the single character rather than a string representation of the Unicode character? At the moment, as you can see, the database is storing the literal characters, not the unicode value.

3) If not, you could store it as an integral type and cast it to a char when you read it into your Java program. To me either of these solutions seems like less of a hassle than you current solution.

Layne
[ October 24, 2005: Message edited by: Layne Lund ]
 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code snip by eric seems the only likely way, unicodes are decoded at compile time, there's no way you can have a string "\u0012" with its unicode meaning at runtime- it wil just be a srting of 6 chars.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic