• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unicode Charaters from a database

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic