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

前端 未结 5 1814
醉酒成梦
醉酒成梦 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:50

    I have used CHR(63) in my query and that helped resolving my issue.

    Here is what I did for example: select q'[

    ]' from dual;

    This helped getting the string as :

    I have then used this query inside the insert statement, and ran through PreparedStatement. Worked perfectly fine.

    The CHR function is an in built function and can be used similar to other oracle functions. You can use this if you know the query will not going to be repeated lots of times.

提交回复
热议问题