File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling Chinese characters while retriving fromDB using JDBC

 
Arpita Shah
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am displaying this content in combo box
 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic