This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes utf8 to unicode..from browser to oracle db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "utf8 to unicode..from browser to oracle db" Watch "utf8 to unicode..from browser to oracle db" New topic
Author

utf8 to unicode..from browser to oracle db

ayeen zurc
Greenhorn

Joined: Oct 08, 2010
Posts: 3

hi...


how do you convert a utf8 encoding value (not a file) to unicode (default java encoding) value ? ex: the euro sign ( € )
my goal is to be able to display the euro sign (or any unicode value) both in oracle (or maybe also in msql server) and browser....


here's the story...

[scenario 1]
i have a jsp and it has textbox that accepts a value and saves it in the database (oracle) ... let's call my textbox "tb"... now if i type in the euro sign (i type in 20ac using an IME which then displays the euro sign) in the "tb" and hit submit and then i do a search (select *...from..) in oracle the value gets saved as:

â??¬

now if i try to go back to my jsp and try to search that same value (again by typing in 20ac using IME) it returns the correct row and it displays the euro just fine....


i tried looking at the hex equivalent of the euro that i typed:
00e2_0082_00ac <-- which means it's in utf-8 encoding

i also tried to do a dump in oracle and this is what i got:
Typ=1 Len=6: 0,e2,0,82,0,ac




[scenario 2]
i hardcoded the value in my java code instead of typing it in my jsp....so in my code i have this:

String string = "\u20ac";

and then did an insert in oracle...


hex value for that hardcoded string is:
20ac <--- which means it's already in unicode

a dump would give me the same:
Typ=1 Len=2: 20,ac


if i do a select in the database i can see the euro value displayed correctly
but if i do a search via my jsp i would just see this:

?


so what i'm thinking to do is to convert the value from my jsp to unicode (java default) before saving it to oracle database
and if im going to retrieve the values to display it on my jsp i have to convert the unicode values to utf-8.

but my problem is i don't know how to do it..
i tried this:

//from utf8 to unicode
String string= (String) theForm.getValue("tb");
byte[] utf8 = string.getBytes("UTF-8");
String my_unicode = new String(utf8 , "UTF-16");

but it still isn't giving me the correct unicode equivalent

and i tried this to convert from unicode (from oracle value) to utf-8 (to display on browser)

//from unicode to utf8
byte[] utf16 = raw_value.getBytes("UTF-16");
String my_utf8 = new String(utf16 );


Notes:
Oracle is configured as unicode
My browser is set to utf-8 (using the: <meta http-equiv="content-type" content="text/html; charset=utf-8">)
Using Tomcat 6
Using JDK1.5.0_14



P.S.
im attaching a couple images for better visuals of what i was explaining...


thank you so much in advance!
ayeen zurc
Greenhorn

Joined: Oct 08, 2010
Posts: 3
here are the images..



[Thumbnail for hardcoding_the_value.jpg]

ayeen zurc
Greenhorn

Joined: Oct 08, 2010
Posts: 3
and here's using IME



[Thumbnail for usingIME.jpg]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: utf8 to unicode..from browser to oracle db
 
Similar Threads
Problem in displaying unicode data from DB2 in JSP
Few Doubts about encoding
Problem converting form data to UTF-8 on solaris
Reading NVarChar2 from Oracle 10g database
An Unicode (UTF8 : right arrow ->) validation