在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編碼,既然數據最終是要存到數據庫中,
那么首先先要保證數據在程序中時、在數據庫中時的編碼一致;