Java.Sql.Sqlexception: Incorrect String Value: '\Xf0\X9F\X91\Xbd\Xf0\X9F...'

saving emoji to mysql using hibernate Incorrect string value: '\xF0\x9F\x98\x88\xF0\x9F...' for column 'name' at row 1

I Solved it by upgrading the mysql-connector-java to 5.1.49 and adding the following to the connection string

{connection string}?characterEncoding=UTF-8&useUnicode=true

reference:https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html

General error: 1366 Incorrect string value: '\xF0\x9F\x8D\xB8 !...'

Setting your column and table to utf8mb4 is fine, however additional settings are needed for things to work smoothly :

PDO connection :

$dsn = 'mysql:host=my_ip;dbname=my_db;charset=utf8mb4';

SQL order to run after connecting and before running queries :

$conn->exec("set names utf8mb4");

Incorrect string value: '\xF0\x9F\x8E\xB6\xF0\x9F...' MySQL

I was finally able to figure out the issue.
I had to change some settings in mysql configuration my.ini
This article helped a lot
http://mathiasbynens.be/notes/mysql-utf8mb4#character-sets

First i changed the character set in my.ini to utf8mb4
Next i ran the following commands in mysql client

SET NAMES utf8mb4; 
ALTER DATABASE dreams_twitter CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;

Use the following command to check that the changes are made

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';


Related Topics



Leave a reply



Submit