title: Building a dynamic SQL query based on user input in Java
body: <p>If I have a search module which has the following:
  search box, dropdown 1, dropdown 2.</p>
  
  <p>And I have a query like this:</p>
  
  <pre><code>SELECT * FROM MY_TABLE where q1 = 'searchBox' AND q2 = 'dropdown1' AND q3 = 'dropdown2'
  </code></pre>
  
  <p>How can I make that query dynamic depending on user filter, so if the user only fills the search box, the query will be:</p>
  
  <pre><code>SELECT * FROM MY_TABLE where q1 = 'searchBox'
  </code></pre>
  
  <p>If the user fills search box and dropdown1, the query will be:</p>
  
  <pre><code>SELECT * FROM MY_TABLE where q1 = 'searchBox' AND q2 = 'dropdown1'
  </code></pre>
  
  <p>and if the user doesn't fill anything, the query will be:</p>
  
  <pre><code>SELECT * FROM MY_TABLE
  </code></pre>
  
  <p>I am using Java.</p>