I have this query that I’m running in Java.
select book from com where genre=?;
I set the parameter for genre dynamically. Is there a way to sometimes set the parameter so that all data is selected?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The usual trick is to set a separate parameter for selecting everything:
When you set the second parameter to
0, filtering by genre is used, but when you set it to1, everything is returned.If you are willing to switch to using named JDBC parameters, you could rewrite with one parameter, and use
nullto mean “select everything”: