This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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...
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
i hardcoded the value in my java code instead of typing it in my jsp....so in my code i have this:
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 );
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
im attaching a couple images for better visuals of what i was explaining...