Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that java processing database does not support emoji emoji

Shulou Source: shulou.com Published: 2022-05-31 23:36:26 09月14日 Update

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!

Tags: Emoticons data databases support processing content methods storage learning practicality deeper simplicity garbled code interests characters bytes practicality practicality tools Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information NVidia Microsoft Huawei