Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Character decoding in Java

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I need a small help in decoding chineese characters in Java. I'm using oracle as database and in the registration page, I'm entering chineese letters and it gets stored in the database in an encoded form. Now while I want to retrieve it and show some report, I'm not able to decode it. Can anyone please help me with this.

Thanks in advance!
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What encoding are you using? For each encoder there is a corresponding decoder.
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine this chineese character 门阿年年阿嚏和阿人阿胶 gets stored in the database as 门 阿年 年阿嚏 和 阿 人 阿
胶 when I use UTF-8 encoding. When I tried to retrieve it, I'm just not able to display the 门阿年年阿嚏和阿人阿胶 character but instead I see the 门阿年年阿嚏和阿人阿
胶. So all I have to do is decode the result using UTF-8 again. Am I right?
[ November 28, 2007: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

I'm exactly looking for a solution like the one above. When I typed my above post, after the "gets stored in the database as" I wanted to type the encoded form (#3453....a long String like this) of that chineese character but when I paster that encoded form and when I saw my post again, that encoded character got decoded into it's original chineese form. What is the mechanism employed here. Can you please help me...
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you're storing in the DB is UTF-8, then you should not need to do anything. Just display the bytes -as you're getting them from the DB- in the web page, and set the character encoding to UTF-8.
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using an Oracle database and what I'm doing is that, I set the encoding to UTF-8 for firstname field from my java code and send that string to the insert query. Now when I retrieve it do I have to decode that again using UTF-8? Is that the right way to go?
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I set the encoding to UTF-8 for firstname field from my java code and send that string to the insert query.


This sounds fishy. You don't set the encoding for individual fields - you set it once when you create the database. Then it's used for all character data in the whole database.

Now when I retrieve it do I have to decode that again using UTF-8? Is that the right way to go?


No. If what is stored in the database is in UTF-8, then it will be read correctly into Java strings; the application doesn't have to do anything.
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,

So doing the following would be enough??

set <%@page pageEncoding="UTF-8"%> in my jsp and just do normal inserts (chineese letters) using sql and when I view the results again in my jsp, I will see the original text in chineese. Please let me know!
 
    Bookmark Topic Watch Topic
  • New Topic