Data removed from the network can not be inserted into the database after parsing, prompting a field problem, the problem is as follows:
Sqlexception:incorrect string value: ' \xf0\x9f\x98\x84 ' for column ' Wei_content ' at row 1
After reviewing the data, it was found that the emoji character and database were different and could not be stored directly
Solution One:
Remove the emoji characters from the content:
public string Removenonbmpunicode (String str) { if (str = = null) { return null; } str = Str.replaceall ("[^\\u0000-\\uffff]", ""); return str; }
Solution Two:
Set Database parameters:
1. Convert MySQL encoding from UTF8 to utf8mb4:
Modify the my.cnf in the MySQL installation directory
2. The encoding of the modified data table is UTF8MB4
Execute command: ALTER TABLE table_name CONVERT to CHARACTER SET utf8mb4;
It should be possible to solve the problem at this point.
Emoji character cannot be inserted into MySQL database, prompting "' \xf0\x9f\x98\x84 ' for column ' XXXX ' at row 1"