3

I am trying to save tweets into MySql db, most of the time it works fine, but when tweet's like the ones given below come,

Example 1 Example 2

I get the following exception from MySql,

java.sql.BatchUpdateException: Incorrect string value: '\xF0\x9F\x92\xB2\xF0\x9F...' for column 'twtText' at row 1

How can we handle such texts.

Cool Techie
  • 756
  • 2
  • 18
  • 39

4 Answers4

1

This works for me. Changing the character set in MySql

ALTER TABLE TableName MODIFY COLUMN ColumnName varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
hotzst
  • 7,238
  • 9
  • 41
  • 64
Vang Lian
  • 11
  • 1
0

Try changing your column's charset to the value reflecting the charset of the strings you want to insert.

Example:

ALTER TABLE database.table MODIFY COLUMN col VARCHAR(255)  CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
cassi.lup
  • 1,261
  • 7
  • 23
0

Besides setting the collation on the database table / column, we also had to set on the client, in the app, the collation with: SET NAMES 'utf8mb4';

before the actual statement . Similar errors: Incorrect string value: '\xF0\x9F\x8E\xB6\xF0\x9F...' MySQL

Community
  • 1
  • 1
devplayer
  • 587
  • 4
  • 12
0

I got the same issure and solveld it. The cause of the error is that the string contains emoticons.

  1. set your mysql column's charset to utf8mb4 and Collation to utf8mb4_general_ci
  2. set your connection string of charset to utf8mb4 like charset=utf8mb4
  3. ok, test it
Leafney
  • 339
  • 3
  • 8