开发者

Use of LIKE clause in sql prepared statement, spring, SimpleJDBCTemplate

I have the following sql prepared statement:

SELECT * FROM video WHERE video_name LIKE ?

Im using spring and jdbc. i have a method, where term is a searchterm, sjt is a SimpleJdbcTemplate, VideoMapper is a RowMapper and searchForTermQuery is the string from above

...
return sjt.query(searchForTermQuery, new VideoMapper(), term);

My table h开发者_高级运维as 2 videos that match the term. However when I run the query none is found. I get an empty List.

I tried playing with % around the question mark, but it only gave badGrammarExceptions.


You need to put the % around the value itself, not around the placeholder (the question mark).

So:

return sjt.query(searchForTermQuery, new VideoMapper(), "%" + term + "%");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜