1

这是示例代码:

CREATE DATABASE test_unicode DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

USE test_unicode;

CREATE TABLE simple_table (text varchar(100) NOT NULL);

INSERT INTO simple_table VALUES ('l\u2019agave');

SELECT * FROM simple_table;

这是输出:

+-------------+
| text        |
+-------------+
| lu2019agave |
+-------------+
1 row in set (0.00 sec)

Mysql存储我的字符串没有 - “ \

我需要得到“l\u2019agave”与 - “ \

我该怎么做?

我尝试了很多对mysql的编码设置,但它对我不起作用......

感谢您的建议!

4

3 回答 3

4

尝试

INSERT INTO simple_table VALUES ('l\\u2019agave');
于 2013-07-08T11:06:45.823 回答
1

尝试这个 :

INSERT INTO `test_unicode`.`simple_table` (`text`) VALUES ('l\\u2019agave'); 

This is because MySQL uses C escape syntax in strings (for example, “\n” to represent a newline character), you must double any “\” that you use in LIKE strings. For example, to search for “\n”, specify it as “\n”. To search for “\”, specify it as “\\”; this is because the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched against.

于 2013-07-08T11:47:51.720 回答
0

对于 java: org.apache.commons.lang3.StringEscapeUtils.unescapeJava(str);将转义的 Unicode 字符转换回实际字符

于 2016-09-09T05:06:41.820 回答