title: Dynamic SQL Query in Java
body: <p>I have a function</p>
  
  <pre><code>public void executeMyQuery(Connection con) {
      PreparedStatement ps = con.prepareStatement("SELECT * FROM STUDENT WHERE ID = ?");
      ps.setInt(1, 7);
      ps.executeQuery();
  }
  </code></pre>
  
  <p>if i will run this it will work fine. But I want to do like this.  </p>
  
  <ol>
  <li>if I will setInt it should include WHERE clause. (returns matched
  row)</li>
  <li>if I don't setInt it should exclude WHERE clause. (returns whole table)</li>
  </ol>
  
  <p>Or is there is any way to dynamically remove or modify the string after WHERE Clause.</p>