当前位置:网站首页>What if MySQL fails to store emoticons
What if MySQL fails to store emoticons
2022-06-29 22:32:00 【The road is blocked and long - the line will come - the line wi】
Catalog
Preface
Abnormal information :
### The error occurred while setting parameters ### SQL: INSERT INTO news_info ( id, title, content, author, summary, sensitives, scraping_time, level, news_type, content_text, original_columns, content_words ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
### Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\x89' for column 'author' at row 1 ;
uncategorized SQLException; SQL state [HY000];
error code [1366];
Incorrect string value: '\xF0\x9F\x91\x89' for column 'author' at row 1;
nested exception is java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\x89' for column 'author' at row 1 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
The main reason is
author Contains emoticons , The expression is 4 character , If Mysql When creating the database and tables, there is no statement that 4 byte , So it's in insert I'll make a mistake !
terms of settlement
It needs to be done during consumption warehousing author Convert to normal binary , Two character Chinese characters , That is to eliminate the four byte expression ;
String author= ContentUtils.filterOffUtf8Mb(newsInfo.getAuthor()); newsInfo.setAuthor(author);
The main tool code
/**
* The main function is to do facial expression package elimination tools
* @param text
* @return
*/
public static String filterOffUtf8Mb(String text) {
if (StringUtils.isBlank(text)) {
return text;
}
String result = text;
try {
byte[] bytes = text.getBytes(UTF_CHARACTOR);
ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
int i = 0;
while (i < bytes.length) {
short b = bytes[i];
if (b > 0) {
buffer.put(bytes[i++]);
continue;
}
// Remove sign bit
b += 256;
if (((b >> 5) ^ 0x06) == 0) {
buffer.put(bytes, i, 2);
i += 2;
} else if (((b >> 4) ^ 0x0E) == 0) {
buffer.put(bytes, i, 3);
i += 3;
} else if (((b >> 3) ^ 0x1E) == 0) {
i += 4;
} else if (((b >> 2) ^ 0xBE) == 0) {
i += 5;
} else {
i += 6;
}
}
buffer.flip();
result = new String(buffer.array(), UTF_CHARACTOR);
} catch (Exception ex) {
log.error(" Content filtering 4 Error in byte character " + ex.getMessage());
}
return result;
}
边栏推荐
- Grep tool
- Static keyword continuation, inheritance, rewrite, polymorphism
- Data mining review
- Detailed description of gaussdb (DWS) complex and diverse resource load management methods
- MySQL,MVCC详解,快照读在RC、RR下的区别
- mysql备份数据库linux
- 5-minute quick start pytest testing framework
- MySQL lock common knowledge points & summary of interview questions
- If I am in Zhuhai, where can I open an account? Is it safe to open an account online?
- MySQL 锁常见知识点&面试题总结
猜你喜欢
Kubernetes architecture that novices must know
Realizing deep learning framework from zero -- LSTM from theory to practice [theory]
MySQL lock common knowledge points & summary of interview questions
Detailed explanation of MySQL and mvcc and the difference between RC and RR for snapshot reading
Huawei cloud AOM version 2.0 release
A mysql IBD file is too large processing record
math_基本初等函数图型(幂函数/指数/对数/三角/反三角)
把数组排成最小的数_数组中的逆序对(归并统计法)_数字在升序数组中出现的次数_丑数(剑指offer)
math_ Basic elementary function graph (power function / exponent / logarithm / trigonometry / inverse trigonometry)
Vs2013 how to make the program run on other computers
随机推荐
The database of the server cannot be connected [the service has been started, the firewall has been closed, the port has been opened, and the netlent port is not connected]
5 - 1 Analyse de vulnérabilité du système
免费将pdf转换成word的软件分享,这几个软件一定要知道!
稳!上千微服务接入 Zadig 的最佳姿势(Helm Chart 篇)
jfinal中如何使用过滤器监控Druid监听SQL执行?
中国数据库崛起,阿里云李飞飞:中国云数据库多种主流技术创新已领先国外
华为云AOM 2.0版本发布
如果我在珠海,到哪里开户比较好?究竟网上开户是否安全么?
科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度
Is it appropriate to apply silicone paint to American Standard UL 790 class a?
联通入库|需要各地联通公司销售其产品的都需要先入总库
Day9 ---- 用户注册与登录
Guangzhou launched a campaign to promote the safety of bottled gas and popularized the knowledge of gas safety
新手必须知道的 Kubernetes 架构
软件快速交付真的需要以安全为代价吗?
一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】
Common PostgreSQL data operation notes: time
Build a short video platform, fade in and fade out, and support left sliding and right pulley to broadcast pictures
5-1系统漏洞扫描
[php8+oracle11g+windows environment without tools] Intranet / no network /win10/php connecting to Oracle database instance