简体   繁体   中英

Storing Unicode and special characters in MySQL tables

My current requirement is to store Unicode and other special characters, such as double quotes in MySQL tables. For that purpose, as many have suggested, we should use Apache's StringEscapeUtils.escapeJava() method. The problem is, although this method does replace special characters with their respective unicodes (\\uxxxx), the MySQL table stores them as uxxxx and not \\uxxxx. Due to this, when I try to decode it while fetching from the database, StringEscapeUtils.unescapeJava() fails (since it cannot find the '\\').

Here are my questions:

  1. Why is it happening (that is, '\\' are skipped by the table).
  2. What is the solution for this?

Don't use Unicode "codepoints" ( \\uxxxx ), use UTF8.

Dont' use any special functions. Instead announce that everything is UTF-8 ( utf8mb4 in MySQL).

See Best Practice

(If you are being provided \\uxxxx , then you are stuck with converting to utf8 first. If your real question is on how to convert, then ask it that way.) `

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM