0

Sorry I know the title of this question doesn't make any sense.

The problem is that I have database column is 100 varchar in size. I want to insert value with mix of Chinese and English in 1 String, I need to check the length of the String in my java code in case I need to truncate it. Since 1 Chinese char takes 3 varchars, is there an easy way I can find out how many varchars is needed in my String?

Thanks,

topcan5
  • 1,511
  • 8
  • 30
  • 54
  • 1
    What database are you using, and what are the settings? For example, if we know that the limit is *actually* in terms of UTF-8 bytes, then it's easy. – Jon Skeet Jun 28 '13 at 17:02

1 Answers1

3

You could call getBytes(CharSet).length on the string to find out how many bytes it represents. That is usually how many characters it would take in a DB.

Kazar
  • 56
  • 2