aspose file tools*
The moose likes JDBC and the fly likes Handling Chinese characters while retriving fromDB using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Handling Chinese characters while retriving fromDB using JDBC" Watch "Handling Chinese characters while retriving fromDB using JDBC" New topic
Author

Handling Chinese characters while retriving fromDB using JDBC

Arpita Shah
Greenhorn

Joined: Aug 28, 2009
Posts: 15
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Arpita Shah
Greenhorn

Joined: Aug 28, 2009
Posts: 15
I am displaying this content in combo box
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Aug 28, 2009
Posts: 15
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Aug 28, 2009
Posts: 15
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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?


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling Chinese characters while retriving fromDB using JDBC