This is how my connection is set:
Connection conn = DriverManager.getConnection(url + dbName + "?useUnicode=true&characterEncoding=utf-8", userName, password);
And I'm getting the following error when tyring to add a row to a table:
Incorrect string value: '\xF0\x90\x8D\x83\xF0\x90...' for column 'content' at row 1
I'm inserting thousands of records, and I always get this error when the text contains \xF0 (i.e. the the incorrect string value always starts with \xF0).
The column's collation is utf8_general_ci.
What could be the problem?
I had this problem with my PLAY Java application. This is my stack trace for that exception:
I was trying to save a record using io.Ebean. I fixed it by re creating my database with utf8mb4 collation, and applied play evolution to re create all tables so that all tables should be recreated with utf-8 collation.
Its mostly caused due to some unicode characters. In my case it was the Rupee currency symbol.
To quickly fix this, I had to spot the character causing this error. I copy pasted the entire text in a text editor like vi and replaced the troubling character with a text one.
I had the same problem in my rails project:
Solution 1: before saving to db convert string to base64 by
Base64.encode64(subject)
and after fetching from db useBase64.decode64(subject)
Solution 2:
Step 1: Change the character set (and collation) for subject column by
Step 2: In database.yml use
Assuming you are using phpmyadmin to solve this error, follow these steps:
latin1_swedish_ci
(or whatever it is) toutf8_general_ci
my solution is change the column type from varchar(255) to blob
I wanted to combine a couple of posts to make a full answer of this since it does appear to be a few steps.
/etc/mysql/my.cnf
or/etc/mysql/mysql.conf.d/mysqld.cnf
Again from advice above all jdbc connections had
characterEncoding=UTF-8
andcharacterSetResults=UTF-8
removed from themWith this set
-Dfile.encoding=UTF-8
appeared to make no difference.I could still not write international text into db getting same failure as above
Now using this how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8
Update all your db to use
utf8mb4
Run this query that gives you what needs to be rung
Copy paste output in editor replace all | with nothing post back into mysql when connected to correct db.
That is all that had to be done and all seems to work for me. Not the -
Dfile.encoding=UTF-8
is not enabled and it appears to work as expectedE2A Still having an issue ? I certainly am in production so it turns out you do need to check over what has been done by above, since it sometimes does not work, here is reason and fix in this scenario:
You can see some are still latin attempting to manually update the record:
So let's narrow it down:
In short I had to reduce the size of that field in order to get the update to work.
Now when I run:
It all works