Solve emoji storage MySQL error problem

Source: Internet
Author: User

Before the solution, you have to explain why there is an error, emoji expression occupies 4 bytes, but MySQL database UTF-8 encoding can only store 3 bytes, it will cause storage not to go in

How to troubleshoot emoji storage issues

MySQL UTF8 encodes a character up to 3 bytes, but a emoji expression is 4 bytes, so UTF8 does not support storing emoji emoticons. But UTF8 's superset utf8mb4 a character can have up to 4 bytes, so it can support the storage of emoji expression. But to modify this configuration is too cumbersome, error-prone, Emoji-java This library can solve this problem in the code snippet, to solve the idea:

    • The page has an expression??, after processing can be??, the character into the database
    • When you read it, you can use it. This character is converted to??

For example:?? I can store as: smile:,?? Stored as: cry:, etc., can be mapped like this.

1. Introduction of dependency
1 <dependency>2      <groupId>com.vdurmont</groupId>3      < Artifactid>emoji-java</artifactid>4     <version>3.2.0</version>5 </ Dependency>
2. Usage
String nikenametmp = Resultjson.get ("nickname"= emojiparser.parsetoaliases (nikenametmp);//convert emoji to characters

Use the following two methods to convert one another:

Emojiparser.parsetoaliases (string); Convert emoji to Characters

Emojiparser.parsetounicode (string); Convert character to emoji

Solve emoji storage MySQL error problem

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.