java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x94"
来源:互联网 发布:看图纸软件 编辑:程序博客网 时间:2024/04/20 01:25
错误提示:java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x94"
原因是Mysql里UTF8编码最多只能支持3个字节,而Emoji表情字符使用的UTF8编码,很多都是4个字节,有些甚至是6个字节。
解决的方案有两种:
1.使用utf8mb4的mysql编码来容纳这些字符。
2.过滤掉这些特殊的表情字符。
关于第一种解决方法,请参考:http://segmentfault.com/a/1190000000616820 和 http://info.michael-simons.eu/2013/01/21/Java-mysql-and-multi-byte-utf-8-support/
有大量细节需要注意,例如:mysql版本,mysql的配置,mysql connector的版本等等。。
因为我们使用的云数据库,所以我选择了过滤这些特殊字符。其实过滤的方式很简单,直接使用正则表达式匹配编码范围,然后替换就行了。
下面是代码。
public static String filterEmoji(String source) { if(source != null) { Pattern emoji = Pattern.compile ("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",Pattern.UNICODE_CASE | Pattern . CASE_INSENSITIVE ) ; Matcher emojiMatcher = emoji.matcher(source); if ( emojiMatcher.find()) { source = emojiMatcher.replaceAll("*"); return source ; } return source; } return source; }
来源1
来源2
0 0
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x94"
- mysql的utf8mb4编码以及java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' 问题的处理
- SQLException: Incorrect string value: '\xF0\x9F\x91\x8D\xF0\x9F...'
- 关于mysql的java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F…'问题
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8E' for column 'nick' at row 1
- MySQL java.sql.SQLException: Incorrect string value: '\xF0\x9F\xA4\x97' for column
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column 'Content' at row 1
- Mysql插入数据报错java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8D\xE8\xBE...'
- Mysql插入数据报错java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8D\xE8\xBE...'
- Incorrect string value: '\xF0\x9F\x92\x90</...' for column 'xxx' at row 1
- Incorrect string value: '\xF0\x9F\x92\x90</...' for column 'xxx' at row 1
- Incorrect string value: '\xF0\x9F\x90\x9D</...' for column 'content' at row 1
- java.sql.BatchUpdateException: Incorrect string value: '\xF0\x9D\x94\xB9+)...' for column 'title' at
- java.sql.BatchUpdateException: Incorrect string value: '\xF0\x9D\x94\xB9+)...' for column 'NAME_' at
- Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F
- Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F
- mysql Incorrect string value \xF0\x9F\x98\x84\xF0\x9F
- Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F
- 图像特征点匹配(Matching feature points) to be continued..
- 6.2.2
- Mathematica 矩阵常用函数
- 康托展开之我排第几个与裸康托逆展开之nyoj143
- Leetcode16. 3Sum Closest
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x94"
- 完美解决Kindeditor 4.1.7在IE11下复制一段内容想粘贴到中间总是变成粘贴到最后的bug
- 将博客搬至CSDN
- Python学习资料
- c++ Primer 中文版 第五版 编译
- java poi 在excel中插入图片
- Couldn't find preset “es2015” relative to directory
- js实现继承的几种方式
- Web前端之面试题