Incorrect string value:'\xF0\x9F\x8C\xB8' for column'fullname' at row 1 Detailed explanation of the error

Guide

  • Such an error was reported when the database was stored. The reason is that the entry field contains an emoji expression.
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x8C\xB8' for column 'fullname' at row 1

Handling method

  • Change the database encoding set to utf8mb4.

Detailed explanation of utf8mb4

  • MySQL added this utf8mb4 encoding after version 5.5.3.
  • utf8mb4 is a superset of utf8. In theory, the original utf8 is used, and then the character set is modified to utf8mb4, which will not cause any problems in reading the existing utf8 encoding.
  • mb4 is the abbreviation of most bytes 4, specially used to be compatible with four-byte unicode.
  • utf8 encoding, the maximum character length is 3 bytes, if you encounter a 4 byte character, an error will occur.
  • The maximum Unicode character that can be encoded by three-byte UTF-8 is 0xFFFF, which is the Basic Multitext Plane (BMP) in Unicode. Emoji expressions, some rarely used Chinese characters, and any newly added Unicode characters are not part of BMP.
  • You can use the utf8mb4 character encoding to directly store emoj expressions instead of storing the replacement characters of the expressions.
  • For better compatibility, utf8mb4 should be used instead of utf8.
  • For CHAR type data, using utf8mb4 storage will consume more space.

The above text is summarized from

Original link: http://blog.xieyc.com/utf8-and-utf8mb4/

Guess you like

Origin blog.csdn.net/u010318957/article/details/80433608