往MySQL插入数据时,报错如下

java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\x88\xE6\x88...' for column 'content' at row  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:) at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:) at 

因为emoji表情导致,有两种解决方法

一、过滤掉字段中的emoji

import org.apache.commons.lang.StringUtils;

/**
* @author: FengZhen
* @create: 2019-02-25
*/
public class EmojiFilter { private static boolean isEmojiCharacter(char codePoint) {
return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA)
|| (codePoint == 0xD)
|| ((codePoint >= 0x20) && (codePoint <= 0xD7FF))
|| ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
|| ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
} /**
* 过滤emoji 或者 其他非文字类型的字符
*
* @param source
* @return
*/
public static String filterEmoji(String source) {
if (StringUtils.isBlank(source)) {
return source;
}
StringBuilder buf = null;
int len = source.length();
for (int i = ; i < len; i++) {
char codePoint = source.charAt(i);
if (isEmojiCharacter(codePoint)) {
if (buf == null) {
buf = new StringBuilder(source.length());
}
buf.append(codePoint);
}
}
if (buf == null) {
return source;
} else {
if (buf.length() == len) {
buf = null;
return source;
} else {
return buf.toString();
}
}
}
}

二、将表编码设置为utf8mb4

若需还原展示该字段,则建议此种方式。

java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\x88\xE6\x88...' for column 'content' at row 1的更多相关文章

  1. Mysql插入数据报错java.sql.SQLException: Incorrect string value: '\xF0\x9F\x93\x8D\xE6\x88...'

    今天读取solr里面的数据,往mysql插入时报错, Incorrect string value: '\xF0\x9F\x93\x8D\xE8\x88...' for column 'title'  ...

  2. java.sql.SQLException: Incorrect string value: '\xE5\xBC\xA0\xE9\x9B\xB7' for column 'content' at row 1

    这个问题主要是由于该字段及腹肌编码不正确导致的,一般新建的表如果没设置就会是latin1字符集需要将表改为utf8字符集,再将报错的列的字符集改为utf8即可,修改命令如下所示: ALTER TABL ...

  3. 表情存储异常--mybatis抛出异常(java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for column 'name' at row 1)

    文章参考 https://blog.csdn.net/junsure2012/article/details/42171035 https://www.cnblogs.com/WangYunShuai ...

  4. java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8E' for column 'nick' at row 1

    java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8E' for column 'nick' at row 1 mysql报错 ...

  5. java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column 'Content' at row 1

    在尝试将 emoji 表情符号 插入MySQL数据库时,遇到以下错误信息: ### The error occurred while setting parameters ### SQL: INSER ...

  6. java.sql.SQLException: Incorrect string value: '\xF0\x9F\x9A\x80\xF0\x9F...' for column 'name' at row 1

    1.异常提示: 12:59:10.000 [http-nio-8080-exec-40] DEBUG o.s.j.s.SQLStateSQLExceptionTranslator - Extracte ...

  7. 带emoji表情弹出层的评论框,semantic+emoji picker,java.sql.SQLException: Incorrect string value: '\xF0\x9F..'

    在自己做一个项目玩时,在做评论的时候. 选中了semantic.js原型,这个在国内用的不是很多,但是在github上star数量很高,想当初我想找一个js框架是就在上面找的. semantic中文网 ...

  8. mybatis抛出异常(java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for column 'name' at row 1)

    文章参考 https://blog.csdn.net/junsure2012/article/details/42171035 https://www.cnblogs.com/WangYunShuai ...

  9. MySql中报错:java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xBB' for column

    问题描述: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xBB' for column 'nickName' at row ...

随机推荐

  1. redis字典的底层实现hashTable

    Redis的字典使用哈希表作为底层实现.一个哈希表里面可以有多个哈希表节点,而每个哈希表节点就保存了字典中的一个键值对 哈希表的数据结构为 table属性是一个数组,数组中的每个元素都是指向dictE ...

  2. PHPFastCGI进程管理器PHP

    PHP-FPM是一个PHPFastCGI进程管理器,是只用于PHP的.      PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中.必须将它patch到你的PH ...

  3. 【BZOJ2482】[Spoj1557] Can you answer these queries II 线段树

    [BZOJ2482][Spoj1557] Can you answer these queries II Description 给定n个元素的序列. 给出m个询问:求l[i]~r[i]的最大子段和( ...

  4. Reverse and Compare(DP)

    Reverse and Compare Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Yo ...

  5. 《挑战程序设计竞赛》1.6 轻松热身 POJ1852

    Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12782   Accepted: 5596 Description ...

  6. Shiro 页面权限标签

    http://www.cnblogs.com/jifeng/p/4500410.html  不整理了,直接看人家写好的

  7. WordArray (An array of 32-bit words.

    CryptoJS中WordArray - qiqi715 - 博客园 http://www.cnblogs.com/qiqi715/p/9623421.html

  8. php自定义函数: 时间转换成智能形式

    function time_trans($paratime,$suffix=false){ $now_time = time(); $dur = $now_time - $paratime; $suf ...

  9. PAT 1070. 结绳(25)

    给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连.每次串连后,原来两段绳子的长度 ...

  10. Android学习笔记之AndroidManifest.xml文件解析(详解)

    一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...