当前位置:网站首页>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;
}边栏推荐
- 联通入库|需要各地联通公司销售其产品的都需要先入总库
- 架构实战营毕业总结
- Why does copying files on a shared folder on a local area network (ERP server) result in the loss of the local Internet
- leetcode:91. 解码方法【dfs + 记忆化】
- Cout ambiguous problem
- Common PostgreSQL data operation notes: time
- 解题元宇宙,网络游戏中的多元通信方案
- 交友平台小程序制作开发代码分享
- Simple understanding of why to rewrite hashcode and equals methods at the same time
- 动态规划学习(持续更新)
猜你喜欢

Digital tracking analysis of insurance services in the first quarter of 2022

AI场景存储优化:云知声超算平台基于 JuiceFS 的存储实践

云原生爱好者周刊:炫酷的 Grafana 监控面板集合

What are the software testing methods and technical knowledge points?

Daily question brushing record (VIII)

Arrange the array into the smallest number_ Reverse pairs in an array (merge Statistics)_ Number of occurrences of a number in an ascending array_ Ugly number (Sword finger offer)

With the rise of China's database, Alibaba cloud lifeifei: China's cloud database has taken the lead in various mainstream technological innovations abroad

稳!上千微服务接入 Zadig 的最佳姿势(Helm Chart 篇)

Underlying principles of file operations (file descriptors and buffers)

细说GaussDB(DWS)复杂多样的资源负载管理手段
随机推荐
leetcode:91. 解码方法【dfs + 记忆化】
Can you be a coder if you don't learn English well? Stop worrying and learn it first
26 years old, 0 basic career change software test, from 3K to 16K monthly salary, a super complete learning guide compiled by me
One click file sharing software jirafeau
IFLYTEK AI learning machine summer new product launch AI + education depth combination to create a new height of products
Daily question brushing record (VIII)
[multithreading] how to implement timer by yourself
Detailed description of gaussdb (DWS) complex and diverse resource load management methods
这次跟大家聊聊技术,也聊聊人生
Common PostgreSQL data operation notes: time
软件快速交付真的需要以安全为代价吗?
【多线程】 如何自己实现定时器
每日刷题记录 (八)
Live broadcast platform development, enter the visual area to execute animation, dynamic effects and add style class names
A mysql IBD file is too large processing record
static关键字续、继承、重写、多态
细说GaussDB(DWS)复杂多样的资源负载管理手段
Does rapid software delivery really need to be at the cost of security?
研发测试时间比,BUG数据分析
Spark cluster installation