6

I try to save twitter feeds in mysql database in the following table

 CREATE TABLE `tweets` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `tweetcontent` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
  PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

but the following error has appeared

            java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8F'
                             for column  'tweetcontent' at row 1 

Can anyone help me please?

ali ali
  • 89
  • 1
  • 1
  • 5
  • This post is useful for you: http://stackoverflow.com/questions/8709892/mysql-throws-incorrect-string-value-error – Musich87 Nov 26 '14 at 11:14

1 Answers1

5

Already answered here

MySQL's utf8 permits only the Unicode characters that can be represented with 3 bytes in UTF-8. Here you have a character that needs 4 bytes: \xF0\x90\x8D\x83 (U+10343 GOTHIC LETTER SAUIL).

If you have MySQL 5.5 or later you can change the column encoding from utf8 to utf8mb4. This encoding allows storage of characters that occupy 4 bytes in UTF-8.

You may also have to set the server property character_encoding_server to utf8mb4 in the MySQL configuration file. It seems that Connector/J defaults to 3-byte Unicode otherwise:

For example, to use 4-byte UTF-8 character sets with Connector/J, configure the MySQL server with character_set_server=utf8mb4, and leave characterEncoding out of the Connector/J connection string. Connector/J will then autodetect the UTF-8 setting.

Community
  • 1
  • 1
prem
  • 3,348
  • 1
  • 25
  • 57