0

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?
Prashant Pandey
  • 4,332
  • 3
  • 26
  • 44

1 Answers1

0

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.) `

Rick James
  • 135,179
  • 13
  • 127
  • 222