-1

I have a very simple SQL query I need to run

SELECT `id`, `{Document id}` FROM `test`.`test` LIMIT 10;

where {Document id} is a column name. Whenever I run it through MariaDB JDBC, it fails with error unknown escape sequence. From my understanding {CALL ...} is used to call stored procedure with a JDBC CallableStatement.

How do I escape it? I want JDBC to treat it as literal string without special meaning. \ didn't work for me.

As mentioned in deleted answer by @a_horse_with_no_name, there is setEscapeProcessing. But it's not supported by a lot of connectors (example MariaDB).

7
  • Which JDBC driver are you using? I guess MySQL Connector/J, or are you really using the deprecated JdbcOdbc bridge? It seems a limitation (bug?) of that driver that it doesn't ignore something that looks like an escape within a quoted column name. Jun 15, 2018 at 12:11
  • So you are using the MariaDB connector, and not ODBC? Jun 15, 2018 at 14:07
  • As per mariaDB documentaion PreparedStatement are always escaped, so try PreparedStatement if you are using Statement.
    – Red Boy
    Jun 15, 2018 at 14:07
  • Instead of `{Document Id}` one might try "{Document Id}" as double quotes are the standard SQL name escapes, backtick is MySQL specific.
    – Joop Eggen
    Jun 15, 2018 at 14:16
  • I am unable to reproduce your issue with mysql-connector-java-5.1.44. ResultSet rs = st.executeQuery("SELECT `{Document id}` FROM test.test"); works fine for me. Jun 17, 2018 at 0:35

1 Answer 1

0

I have confirmed this issue using mariadb-java-client-2.2.5. It is not an issue with mysql-connector-java-5.1.44 so you might want to report this issue to MariaDB.

Following the suggestion by @JoopEggen in the comments above, I got it to work with MariaDB JDBC by adding sessionVariables=sql_mode=ANSI_QUOTES to the connection string and using

ResultSet rs = st.executeQuery("SELECT \"{Document id}\" FROM test.test");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.