• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem While storing Chinese Chars In db.  RSS feed

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am storing Chinese chars in database. The code which I am using to store Chinese chars are

String unicodeStr="\u6c49\u5b57/\u6f22\u5b57\u4e0d\u6b63\u786e";
pstmt = (oracle.jdbc.OraclePreparedStatement)conn.prepareStatement(query);
pstmt.setFormOfUse(1, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);
pstmt.setString(1, unicodeStr);
pstmt.execute();
pstmt.close();
if I hard code unicodeStr as shown above, program stores Unicode chars perfectly
and also display Chinese chars on dos panel perfectly.
But when I try to fetch same Unicode chars (unicodeStr) from file, program stores junk chars in db.
I have converted Chinese chars into Unicode chars (unicodeStr) by using native2ascii tool as shown below

native2ascii Chinese_char.txt uniChinese_char.txt

My OS is window�s XP, file.encoding=GBK and user.language=zh

I also tried String data=new String (unicodeStr.getBytes(), �UTF-8�); but it does not work.
Also if I store unicodeStr in file and then store chars from file in db it stores and displays perfectly.
But if I try to store chars from file converted by native2ascii tool it stores junk chars in db.
Please help me.
Thanks
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open your connection in UTF-8 format. Make sure that the DB CHAR ENCODE is also in UTF-8. To open connection in UTF-8 pass one more parameter with connection properties.

CHARENCODE = utf-8

it may help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!