3

I want to write this query:

SELECT * FROM products
WHERE name LIKE '%?%' 
OR description LIKE '%?%'

and execute it through java in spring web application. But here problem is when I use LIKE operator it has to be with literals, but when I write '%?%' java doesn't recognize ? like placeholders for parameters, when I add parameters I get error that there is no parameters in my query.

Also if I write %?% without literals I get syntax error.

1
  • why can't you use '%:name%' and '%:description%', much better, more readable and resolves your problem Commented Jun 5, 2017 at 17:01

1 Answer 1

7

You can always use concat():

SELECT *
FROM products
WHERE name LIKE CONCAT('%', ?, '%') OR
      description LIKE CONCAT('%', ?, '%');

Or use the application to put the wildcards in the pattern string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.