在oracle中
N开头的字段类型(比如NCHAR,NVARCHAR2)中,任何一个字符(包括一个汉字)占2个字节,统一的。
不以N开头的字段类型(比如CHAR,VARCHAR2)中,unicode字符(比如汉字)占3个字节,其他字符占1个字节。
public static void main(String[] args) throws UnsupportedEncodingException {
String a = "123abc";
int num = a.getBytes("utf-8").length;
System.out.println(num);
a = "中文";
num = a.getBytes("utf-8").length;
System.out.println(num);
}
结果为6和6,为什么转换成utf-8呢,因为数据库使用的是utf-8编码,既然数据最终是要存到数据库中,
那么首先先要保证数据在程序中时、在数据库中时的编码一致;