• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Problem While storing Chinese Chars In db.

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic