Emoji emoji on mobile end failed to insert into MySQL database

Source: Internet
Author: User

Error when inserting data: # # # Error updating database. Cause:Java.sql.SQLException:Incorrect string value: ' \xf0\x9f\x98\x84 ' for column ' Bak2 ' at row 1

This is because: the emoji emoji on the mobile side is 4 bytes, and MySQL's UTF8 encoding is up to 3 bytes, so it's not plugged in.

Workaround:

1: Let the user mainstream, remove those messy expression ... Unlikely

2: Filter out non-mainstream characters ... Not very human

3: The MySQL encoding from UTF8 to UTF8MB4, you can fundamentally solve the problem, specifically how to convert the following articles for reference:
Http://www.it165.net/database/html/201405/6581.html
Http://www.it165.net/database/html/201408/7544.html
Http://www.it165.net/database/html/201408/7550.html
HTTP://WWW.W 2 bc.com/article/8533

4: My solution: Because the database has been built, with a large number of formal data, security, I was by transcoding the way to solve, warehousing before encode a bit, out of the library before decode a bit. Although it is a little cumbersome, the problem can be solved.

Through this matter, give me the revelation: in the rapid development of mobile Internet today, in order to avoid the emoji expression of the failure problem, involving the mobile-related database in the table before the proposed use of the UTF8MB4 character set.
http://m.blog.csdn.net/blog/everything_is_ok/42454451

Emoji emoji on mobile end failed to insert into MySQL database

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.