0

I am doing a project in which I have to save tweets into my MySQL database. The problem is some tweets contains smilies and other symbols which I am not able to save - it shows error like below :

Incorrect string value: '\xF0\x9F\x98\x82. ...' for column 'text' at row 1

I was trying to convert to utf8mb4 using this link tutorial, but in step 5, i have changed my.ini file in my C:\ProgramData\MySQL\MySQL Server 5.6 directory.

But when i do SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; in my mysql console, i am not getting the desire result, my character set is not changed to utf8mb4, it is still utf8, please guide me how to resolve this, i am new to this. I have attached image to the step 5 (Modify connection, client, and server character sets) of the above tutorial.

enter image description here

ratnesh
  • 436
  • 1
  • 5
  • 16
  • Can you try [this solution](http://stackoverflow.com/questions/27828910/php-error-description-incorrect-string-value-xf4t-l-xe9-on-insert) first? – Mjh Sep 07 '15 at 13:47
  • thanks @Mjh it works, but now i don't need to change to `utf8mb4` , right? – ratnesh Sep 07 '15 at 13:59
  • Yes, you are correct, you don't have to change to `utf8mb4`. I'm glad we sorted it! :) – Mjh Sep 07 '15 at 14:13
  • @Mjh , it seems that it did not worked properly, after doing `ps.setString(3, new String(status.getText().getBytes("UTF-8")));` , it is inserting but for some text its showing text too long for my column – ratnesh Sep 10 '15 at 10:58
  • Well, UTF8 can use between 1 and 6 bytes per character. You need to adjust your column length to accommodate for the UTF8 strings. – Mjh Sep 10 '15 at 11:04
  • thanks @Mjh, i had a column called tweets which is of varchar(140), when i changed to varchar(280), that error is not coming, but exactly how many varchar(?), should i put? – ratnesh Sep 10 '15 at 11:53
  • I don't know how many you might need.. you need to calculate that. – Mjh Sep 10 '15 at 12:10

2 Answers2

0

Dup? Need SET NAMES utf8mb4; after connecting.

Rick James
  • 135,179
  • 13
  • 127
  • 222
0

How to avoid Twitter emoticon character while processing string in Java

I just found out, i don't want to save smiley and all, so i am just removing them s = s.replaceAll("[^\\x00-\\x7f-\\x80-\\xad]","")

Community
  • 1
  • 1
ratnesh
  • 436
  • 1
  • 5
  • 16