File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Storing Kanji charaters into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Storing Kanji charaters into database" Watch "Storing Kanji charaters into database" New topic

Storing Kanji charaters into database

Sagar kanchi
Ranch Hand

Joined: Oct 07, 2005
Posts: 50
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?

Where there are more wonders there is less knowledge
I agree. Here's the link:
subject: Storing Kanji charaters into database
It's not a secret anymore!