Completely resolved: Incorrect string value: ' \xf0\x9f\x98\xad ',... ' for column ' Commentcontent ' at row 1

Source: Internet
Author: User

Today, while climbing the NetEase Cloud music song commentary, when inserting data into the MySQL database, incorrect string value: ' \xf0\x9f\x98\xad ',... ' for column ' commentcontent ' Row 1 This error, Google found that the original is due to the database coding problem, because we have a emoj expression in the comment data, and these expressions are encoded in a unit of four bytes, And we usually use the Utf-8 encoding in the MySQL database by default is based on 3 bytes per unit encoding, this is the reason for the data stored in the MySQL database when there is an error, then this question how we should solve it.

I am divided into the following three steps to solve:

(1): Modify the MySQL database code for UFT8MB4

(2): Modify the data table encoding for UTF8MB4

(3): Modify the connection code of the connection database

(1): Modify the MySQL database code for UFT8MB4

To modify the method:

Refer to: http://blog.csdn.net/poice00/article/details/52129351

(2): Modify the data table encoding for UTF8MB4

Execute command: ALTER TABLE table_name CONVERT to CHARACTER SET utf8mb4;

(3): Modify the connection code of the connection database

My original database connection code is:

public static final String URL = "jdbc:mysql://localhost:3306/" +databasename+? useunicode=true&characterencoding =utf8 ";

Modify it to: public static final String URL = "jdbc:mysql://localhost:3306/" +databasename;

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.