Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing Kanji charaters into database

 
Sagar kanchi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to store a String into database that contains some special japanese charaters.
The field on the database side is VARCHAR2(4000)

So, from the java code if String has more than 4000 cahracters am taking first 4000 characters only.

if(str.length() > 4000){
// Take first 4000 chars only
}

This logic did not satisfy the field restrictions on database side if the String contains some special Kanji cahracters. Its giving Exception as the data is too long to fit in.

After that I made the code change as follows as Oracle consider underlying bytes not chars

if(str.getBytes() > 4000){
//Consider characters (from the beginning of String) which
//accounts to less than or equal to 4000 chars
}

It did not work though. The getBytes() and length() is returning the same value.

Any ideas to sahre?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic