Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chinese characters

 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I query a web service, I get values which are sometimes in clear text and sometimes text+chinese characters. I assign the value to a String and when I try to insert it into Oracle database with classes12.jar, I get an "Invalid Character" exception. What could be the problem?

Thanks,
Visu
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What character set is your Oracle database configure to use? If you want to store Chinese characters you will need to use a suitable encoding (Unicode would be easiest).

That aside, if you are actially seeing a error performing the insert my guess is you are not using PreparedStatament? You could try using one instead, see if the error goes away.
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,

The database encoding is utf8. Do we need to add set the encoding in the code also? Is PreparedStatement an option to handle this kind of stuff or is it mandatory?

Visu
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you don't. In Java, all strings are Unicode.

PreparedStatement's avoid any character escaping issues.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic