title: How to create a mutliple search SQL statement where all the parameters are optional?
body: <p>I would like to know if there is any smart way of making a SQL statement for a search engine where there are 5 optional parameters. All parameters can be used or only one of them, or a mix of any of them.. This makes up to 3000+ different combinations.</p>
  
  <p>The statement needs to be prepared to avoid SQL injections.</p>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/4858880/java-jdbc-multi-parameter-search-best-practice">this</a> post, but it dosent quite cut.</p>
  
  <p>What I'm looking for is something like,</p>
  
  <p>String sql =SELECT * FROM table WHERE (optional1)=? AND (optional2)=? AND (optional3)=? AND (optional4)=? AND (optional5)=?</p>
  
  <p>prepared.setString(1, optional1)
  and so on...</p>