“添加时,在索引:: 1处缺少IN或OUT参数?”我查询的参数

时间:2021-12-17 12:43:23

I have a query constructed in Java to select records, and when constructing with the values ?', I'm getting a missing in and out parameter. If I add only ?, it is working properly.

我有一个用Java构造的查询来选择记录,当用值构造时,我得到一个缺少的输入和输出参数。如果我只添加?,它正常工作。

Here is the query where I am setting the ?' value:

这是我设置的查询?'值:

AND 1=fn_contact_account(P.RECORD_ID,'?''%') AND upper( P.PERSON_ID) like ?0 ESCAPE '\' AND NOT (P.PERSON_ID='Unknown')) )

1 个解决方案

#1


Parameters aren't substituted into queries textually. I believe the simplest way to do what you want is to just use the ? on its own for the parameter, but add any leading or trailing values to the parameter itself. For example:

参数不会以文本方式替换为查询。我相信做你想做的最简单的方法就是使用?它本身用于参数,但是将任何前导或尾随值添加到参数本身。例如:

 String sql = "SELECT NAME FROM PERSON WHERE NAME LIKE ?";
 try (PreparedStatement pst = conn.prepareStatement(sql)) {
     // Trailing % for "starts with" behaviour
     pst.setString(1, userInput + "%");
     ...
 }

#1


Parameters aren't substituted into queries textually. I believe the simplest way to do what you want is to just use the ? on its own for the parameter, but add any leading or trailing values to the parameter itself. For example:

参数不会以文本方式替换为查询。我相信做你想做的最简单的方法就是使用?它本身用于参数,但是将任何前导或尾随值添加到参数本身。例如:

 String sql = "SELECT NAME FROM PERSON WHERE NAME LIKE ?";
 try (PreparedStatement pst = conn.prepareStatement(sql)) {
     // Trailing % for "starts with" behaviour
     pst.setString(1, userInput + "%");
     ...
 }