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?
From stackoverflow
combi001
-
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.
From Alnitak -
Can't u make use of parameters inside of using string concatenation ?
From Frederik Gheysels -
cool,
i just set the % signs when setting preparedstatement;
pstmt.setString(1, "%" + name + "%");
From combi001
0 comments:
Post a Comment