当前位置:网站首页>解决 Incorrect string value: ‘\xF0\x9F\x98\xAD“,...‘ for column ‘commentContent‘ at row 1 报错
解决 Incorrect string value: ‘\xF0\x9F\x98\xAD“,...‘ for column ‘commentContent‘ at row 1 报错
2022-07-26 04:30:00 【Rk..】
需求:解析excel表格,将excel中的数据插入到数据库中
在将数据插入数据库中的时候遇到这样一个问题:
### Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xB1\xF0\x9F...' for column 'describe' at row 1
; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\x9F\x90\xB1\xF0\x9F...' for column 'describe' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xB1\xF0\x9F...' for column 'describe' at row 1
离谱的居然是解析表格的前300行没有出现这个错误,到了第301行的时候报了sql异常。首先想到的是会不会第301行的数据会不会有特殊的格式,结果发现并没有,只是数据内容不一样,并没有特殊的格式,排查了半小时,结果是因为数据库的编码不对。
原因在于我们的表格数据中有的被解析成表情了,而这些表情是按照四个字节一个单位进行编码的,而我们通常使用的utf-8编码在mysql数据库中默认是按照3个字节一个单位进行编码的,正是这个原因导致将数据存入mysql数据库的时候出现错误。
我分为下面三个步骤来解决:
(1)、查看mysql数据库的编码
show variables like 'character_set_database';
如果是urf8需要修改为uft8mb4
(2)、修改数据表的编码为utf8mb4
ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb4;也可以直接使用图形化界面更改
(3)、修改连接数据库的连接代码
jdbc:mysql://localhost:3824/reggie?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 修改为: jdbc:mysql://localhost/reggie
边栏推荐
- 三、@RequestMapping注解
- Dijango learning
- mongoDB为什么快
- Solution: runtimeerror: expected object of scalar type int but got scalar type double
- 青少年创客教育的创意设计原理
- Cnosdb Nirvana Rebirth: abandon go and fully embrace rust
- Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
- How to download the supplementary literature?
- egg-sequelize JS编写
- Keil v5安装和使用
猜你喜欢

Wu Enda's machine learning after class exercises - linear regression

青少年创客教育的创意设计原理

二、国际知名项目-HelloWorld

RTSP/Onvif协议视频平台EasyNVR服务一键升级功能的使用教程

一个sql server查询截止某个日期最新的记录

Yapi installation

The auxiliary role of rational cognitive educational robot in teaching and entertainment

MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection

计算离散点的曲率(matlab)

A series of problems about the number of DP paths
随机推荐
Wu Enda's machine learning after class exercises - linear regression
Sweet butter
UE4 多个角色控制权的切换
FFmpeg 视频编码
再获认可 | 赛宁网安连续上榜《CCSIP 2022中国网络安全产业全景图》
MySQL log classification: error log, binary log, query log, slow query log
香甜的黄油
Recognized again | saining network security has been listed in the ccsip 2022 panorama of China's network security industry
生活相关——一个华科研究生导师的肺腑之言(主要适用于理工科)
Swiftui one day crash
3、 @requestmapping annotation
Js手写函数之节流防抖函数
UE4 键盘控制开关灯
青少年创客教育的创意设计原理
1、 Basic introduction
Yadi started to slow down after high-end
[C language foundation] 13 preprocessor
Day24 job
Segger embedded studio cannot find xxx.c or xxx.h file
MySQL only checks the reasons for the slow execution of one line statements