File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Unicode Charaters from a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unicode Charaters from a database" Watch "Unicode Charaters from a database" New topic
Author

Unicode Charaters from a database

John Harris
Greenhorn

Joined: Oct 20, 2005
Posts: 7
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

Joined: Mar 03, 2005
Posts: 26
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

Joined: Dec 06, 2001
Posts: 3061
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 ]

Java API Documentation
The Java Tutorial
Akshay Kiran
Ranch Hand

Joined: Aug 18, 2005
Posts: 220
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.


"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unicode Charaters from a database
 
Similar Threads
utf8 to unicode..from browser to oracle db
java coding and unicode
Unicode problem with Reading XML with utf-8 content into Unicode database
File with euro char
String, UTF-8, Unicode and DB