CREATE TABLE Student(
s_id VARCHAR(20),
s_name VARCHAR(20) NOT NULL DEFAULT ‘’,
s_birth VARCHAR(10) NOT NULL DEFAULT ‘’,
s_sex VARCHAR(10) NOT NULL DEFAULT ‘’,
PRIMARY KEY(s_id)
);
insert into Student values (‘01’ , ‘赵雷’ , ‘1990-01-01’ , ‘男’);
错误信息;
sql> insert into Student values (‘01’ , ‘赵雷’ , ‘1990-01-01’ , ‘男’)
[2019-05-28 20:44:58] [HY000][1366] Incorrect string value: ‘\xE8\xB5\xB5\xE9\x9B\xB7’ for column ‘s_name’ at row 1
纠正方案:
1)修改数据表的编码为utf8mb4
执行命令:ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb
其他网上的方案:
3)在配置文件修改连接数据库的连接代码&characterEncoding=utf8。
jdbc:mysql://localhost:3306/DATABASENAME?useunicode=true
&characterEncoding=utf8