How to put an IN parameter using LIKE using a RowSet?

I have a struggle to get the IN parameter to work inside the LIKE statement for hours! I use CachedRowSet, which, as I understand it, must follow the same rules as PreparedStatement.
Here is the main request:

CachedRowSet cache;
String sql = "SELECT x " +
                "FROM   Y " +
             "WHERE z LIKE '?__'" 

cache.setCommand(sql);
cache.setString(1, "someString");

someString is a well-known identifier, but the database (by the way, PostgreSQL) has an unknown 2 char suffix.

+3
source share
1 answer

Parameter placeholders within quotation marks are ignored. Are they interpreted as literal? ". If you use the parameter, you must put the placeholder in quotation marks in the SQL expression.

LIKE , . :

SELECT x FROM y WHERE z LIKE (? || '__')

"someString" , string '__'.

+5

Source: https://habr.com/ru/post/1702397/


All Articles