[How to Fix]java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x98\x82\xF0\x9F…’

java.sql.SQLException : Incorrect string value: ‘\xF0\x9F\x98\x82\xF0\x9F…’

Problem:
because the emoticons stored in MySQL database string are not compatible with 4-byte Unicode.

Solution:
use the third-party jar to import and store after transformation.

POM introduction:

		 <!-- Expression Switching -->
        <dependency>
            <groupId>com.github.binarywang</groupId>
            <artifactId>java-emoji-converter</artifactId>
            <version>0.1.1</version>
        </dependency>

Specific conversion method:

	String content = "\xF0\x9F\x98\x82\xF0\x9F";
  	EmojiConverter emojiConverter = EmojiConverter.getInstance();
    content= emojiConverter.toAlias(content);//Escaping chat content
    System.out.println(content);

Read More: