简体   繁体   中英

mysql 5.5 invalid escape sequence java

static byte[] ac = {'\\', '\'', '{', '}', '{'}; //not OK insert into tt values('\\\'{}{')
static byte[] ac = {'\\', '\'', '{', '}'}; //OK insert into tt values('\\\'{}')
static byte[] ac = {'\\', '\'', '{'}; //OK insert into tt values('\\\'{')
static byte[] ac = {'\'', '{', '}', '{'}; //OK insert into tt values('\'{}{')
static byte[] ac = {'\\', '{', '}', '{'}; //OK insert into tt values('\\{}{')
  • Ubuntu system
  • MySQL 5.5
  • MySQL JDBC 5.1.22

I am not able to insert 5 bytes to a blob table field, the bytes are shown above. The datasource connection encoding is set to UTF-8 .

Relevant information: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html

Any idea why {} is so special? it works with workbench.

For the not ok, i got the following exception:

java.sql.SQLException: Not a valid escape sequence: {')

This is a bug in some versions of MySQL's JDBC client (Connector/J); see http://bugs.mysql.com/bug.php?id=31457 (and other bugs linked from there). You should be able to fix it by upgrading to the latest Connector/J; alternatively, you can work around it by disabling escape-processing (by writing Statement.setEscapeProcessing(false) ).

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