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