tags:

views:

81

answers:

3

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?

+1  A: 

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.

Alnitak
+1  A: 

Can't u make use of parameters inside of using string concatenation ?

Frederik Gheysels
+1  A: 

cool,

i just set the % signs when setting preparedstatement;

pstmt.setString(1, "%" + name + "%");
combi001