Search code examples
hsqldb

JDBC escape processing and HSQLDB regular expression syntax


What's wrong with this HSQLDB syntax:

 REGEXP_REPLACE(Title, '([0-9]{4})$')

The regular expression is intended to remove 4 digits in parentheses at the end of a string. Thanks for taking a look.

I tried various escaping with no success. Apparently the curly braces are being intercepted by JDBC as an escape sequence of its own.


Solution

  • You can turn JDBC escape processing off.

    Statement statement = connection.createStatement();
    statement.setEscapedProcessing(false);
    statement.executeQuery("select REGEXP_REPLACE(Title, '([0-9]{4})$') from mytable");
    

    The statement.setEscapedProcessing(false) has no effect on a PreparedStatement.