测试1
目标库编码:utf8mb4
目标表:
CREATE TABLE `a` (
`id` int(11) NOT NULL,
`value` mediumtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
@Test
public void test() throws Exception {
String s = "中文";
byte[] gbkBytes = s.getBytes("GBK");
byte[] utf8Bytes = s.getBytes("UTF-8");
// gbkBytes.length == 4
// utf8Bytes.length == 6
// 输出乱码:����
System.out.println("gbk Bytes decode by UTF-8");
System.out.println(new String(gbkBytes, "UTF-8"));
// 输出:中文
System.out.println("gbk Bytes decode by GBK");
System.out.println(new String(gbkBytes, "GBK"));
// 输出:中文
System.out.println("utf8 Bytes decode by UTF-8");
System.out.println(new String(utf8Bytes, "UTF-8"));
// 输出乱码:涓枃
System.out.println("utf8 Bytes decode by GBK");