t_student表:
id | name
1 ÖÐÎÄ_Test001
//从数据库中获取数据
String result = jdbcTemplate.queryForObject("select name from t_student where id = 1", String.class);
//String中char[]的内容: [214,208,206,196,95,84,101,115,116,48,48,49]
//其中214,208代表"中", 206,196代表"文",95代表"_"
//这句话的目的是把char转变为byte,因为ISO-8859-1是按照单字节编码的,只会取出char的低8位.
byte[] arr = result.getBytes("ISO-8859-1");
//arr中的内容是: [-42,-48,-50,-60,95,84,101,115,116,48,48,49]
//与result的char[]中内容是相等的.
//指定arr为GBK格式
String str = new String(arr,"GBK");
//这时str存储的就是UTF-16格式的数据了, 也就是Unicode标识.
//str中char[]的内容是: [4e2d,6587,95,84,101,115,116,48,48,49]
//转成UTF-8字节流格式
byte[] utf_8s = str.getBytes("UTF-8");
//utf_8s中的内容: [-28,-72,-83,-26,-106,-121,95,84,101,115,116,48,48,49]
//-28,-72,-83代表"中"
//-26,-106,-121代表"文"