質問

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,

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top