• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Handling Chinese characters while retriving fromDB using JDBC

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing problem while retriving chinese characters from DB. Chinese characters in DB persisted properly but while retriving it it is showing '?'. Could you please help me out is there any way to retrive data properly with resultSet ?

Thanks in advance.

Arpita.

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arpita Shah wrote:I Chinese characters in DB persisted properly but while retriving it it is showing '?'.


Where are you displaying this Chinese character? Is that display support Unicode character encoding ?
 
Arpita Shah
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am displaying this content in combo box
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arpita Shah wrote:I am displaying this content in combo box


Now again, which combo box? HTML OR Swing JComboBox.
For former:
For later: This is something I never did, but little googling get me plenty of results
Display Unicode in Swing panel
 
Arpita Shah
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Sagar,
Thank you for your reply.

The Problem is I am using HTML and the encoding is set in response as UTF-8 in servlet, still the combo box is showing me boxes instead of chinese characters. I found the root cause is while getting String from ResultSet, the String retrived is in different format I tried with following code and it is working fine

byte[] newVal = rset.getString("TEXT").getBytes("iso-8859-1");
System.out.println(new String(newVal,"UTF-8"));

where rset is ResultSet. But I dont want to do this in java this should be done without writting code. I am using Oracle DB.

Please help for this.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arpita Shah wrote:. But I dont want to do this in java this should be done without writting code.


Why ? You're accessing database using Java, right ? then.. And what do you mean by "without writting code" ?

Also, as the Oracle support Unicode, the problem might be in the first place, that is, the way data get inserted into database, the data might not correctly encoded one.

 
Arpita Shah
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sagar, I mean for not writing code means not to write code for encoding in java for Result Set.

and I checked data in oracle database it is persisted properly. Also I am able to get the same data if I write code in java like this

String newVal =new String(rset.getString("TEXT").getBytes("iso-8859-1"),"UTF-8");
System.out.println(newVal);

For Example : I have data 隐藏技术性错误 in DB and I am getting the same if I write the above code.

I dont want to write such code I want that ResultSet give me directly the same result.

I hope this time I am more clear.

Please let me know if you have any query
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

new String(rset.getString("TEXT").getBytes("iso-8859-1"),"UTF-8")


I find it hard to believe that this code is working correctly for non-ISO-8859 characters. What it does is to convert a string to ISO-8859-encoded bytes, and then convert it back to Unicode while telling the JVM to assume that the bytes are UTF-8 encoded (when they're actually ISO-8859-encoded).

Also, does the client machine have a font installed that contains those characters?
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic