Question

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,

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top