本文主要是介绍charset = latin1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
charset = latin1
使用mybatis插入表数据时,发生报错
Error updating database. Cause: java.sql.SQLException: Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89’ for column ‘name’ at row 1 ### The error may exist in file [/Users/zyf/IdeaProjects/springboot-demo/target/classes/mybatis/mapper/UserMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: insert intouser
(id,name,pwd) values ( ?, ?, ? ) ### Cause: java.sql.SQLException: Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89’ for column ‘name’ at row 1 ; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89’ for column ‘name’ at row 1; nested exception is java.sql.SQLException: Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89’ for column ‘name’ at row 1
非常简单的insert into 语句,怎么就报这个错了
查看了user表的字符集
show create table user
CREATE TABLE `user` (`id` int(11) NOT NULL,`name` varchar(10) CHARACTER SET latin1 DEFAULT NULL,`pwd` varchar(20) CHARACTER SET latin1 DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
怎么是 CHARSET=latin1 ???
latin1 拉丁语 数据库连接url中的 characterEncoding=utf-8 不一致
解决办法
把user表的字符集改成与连接url字符集一致
alter tableuser
chatacter set utf8mb4;
alter tableuser
modify column name varchar(10) character set utf8mb4;
alter tableuser
modify column pwd varchar(20) character set utf8mb4;
在idea中database中建表发生的错
以后注意!!!
这篇关于charset = latin1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!