From Sam Macbeth\'s question:
Is there anything in the JDBC spec which allows a ? to be escaped and be anything other than a parameter placeholder?
I don't see anything in the JDBC specification that would allow ?
to be escaped. Pretty much all it says about ?
is:
Parameter markers, represented by “?” in the SQL string, are used to specify input values to the statement that may vary at runtime. [1]
and later...
Parameter ordinals, which are integers passed to the approriate setter method, refer to the parameter markers ("?") in the statement, starting at one. [2]
And it only defines escape syntax for a small set of features, none of which look like they could be applied to ?
:
JDBC defines escape syntax for the following:
- scalar functions
- date and time literals
- outer joins
- calling stored procedures
- escape characters for LIKE clauses [3]
Overall, it doesn't seem like the JDBC specification has very "strict" language (compared to, for example, some W3C specification documents which use must and should a lot), so I don't know whether a driver which allowed ?
to be escaped would be technically non-compliant, but it would probably be not-so-compatible.
It doesn't even look like even the Postgres driver would allow it, as the method in the driver which actually parses SQL statements for ?
doesn't check for any escape characters.
1. JDBC 4.1 Specification, Section 13.2 — The PreparedStatement
Interface
2. JDBC 4.1 Specification, Section 13.3.2 — Setting Parameters
3. JDBC 4.1 Specification, Section 13.4 — Escape Syntax