Emoji character cannot be inserted into MySQL database, prompting "' \xf0\x9f\x98\x84 ' for column ' XXXX ' at row 1"

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.