How to solve the problem that java processing database does not support emoji emoji
This article mainly explains "java processing database does not support emoji emoticons how to solve", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to solve the problem that the java processing database does not support emoji emoticons.
Generally, utf8,utf8 does not support storing emoji in the database. Garbled code occurs when the stored Wechat nickname contains emoji. There are two solutions:
When the 1.mysql database is upgraded to version 5.5 or above, the characters changed from utf8 to utf8mb4,utf8mb4 can be up to 4 bytes, and the emoji can be stored and the database server can be restarted. This method may fail.
two。 Filter out emoji in java code for simplicity and efficiency. Here are the tool classes for filtering emoji:
Import java.util.regex.Matcher;import java.util.regex.Pattern
Public class EmojiUtil {
Public static String replace (String input) {
If (! StringUtil.isEmpty (input)) {
String patternStr = "[^\ u0000 -\ uFFFF]"
Pattern pattern = Pattern.compile (patternStr, Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE)
Matcher matcher = pattern.matcher (input)
Input = matcher.replaceAll ("")
}
Return input
}
}
At this point, I believe that everyone on the "java processing database does not support emoji emoji how to solve" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!