java存储表情
作者:互联网
一.前言
当我们mysql数据库需要存储表情时,如果不做任何配置则会出现以下错误
Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x80' for column 'content' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) ~[mysql-connector-java-5.1.18.jar:na]
二.数据库
mysql数据的utf-8是一个人尽皆知的bug,他并不是真正的utf-8,而真正的utf-8是utf-8mb4一个字符是四个字节;
三.DataSource配置
<property name="connectionInitSqls" value="set names utf8mb4"/>
标签:存储,jdbc,java,na,connector,MysqlIO,mysql,表情 来源: https://blog.csdn.net/drdongshiye/article/details/100183187