0

I have a long SQL string which has lots of double quotes, which I have to escape before using. Is there an easy way of doing this, like reading the string from a properties file?

FOR E.G.:
SELECT
  (SELECT EXTRACTVALUE(XMLTYPE(COL1), '//p:testRq/policy/testId', 'xmlns:me="wsdl.http://www.example.com/Test", xmlns:ns0="wsdl.http://www.example.com/Test", xmlns:p="http://www.example.com/Test", xmlns:s="http://www.w3.org/2003/05/soap-envelope", xmlns:xsd="http://www.w3.org/2001/XMLSchema", xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", xmlns="http://www.example.com/Test"')
  FROM TESTTABLE
  WHERE TESTID =
    (SELECT MIN(TESTID)
    FROM TABLE2
    WHERE COL1 = COL2
    )
  ) "RESULT"

Ok, it was easy to resolve this. I just created a named-native-query in an orm xml file and used the sql string from there.

shallow
  • 1
  • 3

2 Answers2

0

You could use another character and replace it on the fly.

    String s = "Here's `Some quoted text`".replaceAll("`", "\"");

Here I use a backquote.

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
0

Do use double quotes as an exception.

Try not to use reserved words for table names. If a double quote is mandatory, you will soon receive an SQL syntax error.

With the use of an Object/Relational mapping the SQL is generated, and then the issue would also disappear. (JPA, eclipseLink, mybatis)

I would refrain from storing SQL elsewhere, say in XML files. Bad for development and maintenance.

I would opt for: JOOQ. Writes type-safe SQL by using java as DSL.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • My guess is that the problem is mainly with the parameter to `EXTRACTVALUE` which contains a lot of quotes, not with the `"RESULT"` object name. – Mark Rotteveel Jul 10 '14 at 09:23