I'm trying to pass the following String
to a PreparedStatement
:
private static final String QUICK_SEARCH = "select * from c where NAME like '% ? %'";
However, I get an SQL exception that the bind variable is missing.
Any suggestions?
I'm trying to pass the following String
to a PreparedStatement
:
private static final String QUICK_SEARCH = "select * from c where NAME like '% ? %'";
However, I get an SQL exception that the bind variable is missing.
Any suggestions?
You can't put binding variables inside a string like that.
You need to use:
SELECT * FROM c WHERE name LIKE CONCAT('%', ?, '%')
or similar, depending on what functions are supported by your version of SQL.
Can't u make use of parameters inside of using string concatenation ?
cool,
i just set the % signs when setting preparedstatement;
pstmt.setString(1, "%" + name + "%");