How do I escape a literal question mark ('?') in a JDBC prepared statement

前端 未结 5 1816
醉酒成梦
醉酒成梦 2021-02-19 10:56

I\'d like to create a JDBC PreparedStatement like:

SELECT URL,LOCATE ( \'?\', URL ) pos FROM Links WHERE pageId=? ORDER BY pos ASC

Where the 1s

5条回答
  •  离开以前
    2021-02-19 11:24

    The meaning of the ? is specified in the SQL specification, and the JDBC specification defers to the SQL specification for this.

    A driver doesn't (and shouldn't) interpret a question mark in a literal as a parameter placeholder, as a question mark within a string literal is simply a character within the string literal. For more information look at chapter 5 of SQL:2011 Foundation (ISO-9075-2:2011).

    So escaping is not necessary (nor possible).

提交回复
热议问题