from:
http://*.com/questions/13653712/java-sql-sqlexception-incorrect-string-value-xf0-x9f-x91-xbd-xf0-x9f
http://fatkun.com/2011/05/mysql-alter-charset.html
当MYSQL插入时,出现下面的问题话,基本上是字段的字符集不对,最好用utf8mb4这个字符集。
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F…'
修改字符集的方法如下:(注意:虽然修改了表的字符集,也要修改字段的字符集)
修改数据库字符集:
ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...]; |
把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE ...] |
只是修改表的默认字符集:
ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE...]; |
修改字段的字符集:
ALTER TABLE tbl_name CHANGE c_name c_name CHARACTER SET character_name [COLLATE ...]; |
查看数据库编码:
SHOW CREATE DATABASE db_name; |
查看表编码:
SHOW CREATE TABLE tbl_name; |
查看字段编码:
SHOW FULL COLUMNS FROM tbl_name;