Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

utf8 to unicode..from browser to oracle db  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 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 );

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

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

thank you so much in advance!
ayeen zurc
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here are the images..
[Thumbnail for hardcoding_the_value.jpg]
hard coding the values
ayeen zurc
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and here's using IME
[Thumbnail for usingIME.jpg]
using ime
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!