I have a query like this
SELECT * FROM TABLEA WHERE MODULE = :moduleId AND
UPPER(NAME) LIKE UPPER('%sample''s%') AND ID = :userId;
I escape the apostrophe above with ''. Then pass the sql above to...
Map<
String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("userId", userId);
namedParameterJdbcOperations.queryForList(sql, paramMap, Long.class);
and I got this error:
SQL state [99999]; error code [17041]; Missing IN or OUT parameter at index:: 3; nested exception is java.sql.SQLException: Missing IN or OUT parameter at index:: 3
when looking at the logs, I saw the that the userId was not being replaced by ?
SELECT * FROM TABLEA WHERE MODULE = ?
AND UPPER(NAME) LIKE UPPER('%sample''s%') AND ID = :userId;
Note that the whole string "AND UPPER(NAME) LIKE UPPER('%sample''s%')" is generated by another function, it is concatenated to the whole sql before being run.