title: How to deal with (maybe) null values in a PreparedStatement?
body: <p>The statement is</p>
  
  <pre><code>SELECT * FROM tableA WHERE x = ?
  </code></pre>
  
  <p>and the parameter is inserted via java.sql.PreparedStatement 'stmt'</p>
  
  <pre><code>stmt.setString(1, y); // y may be null
  </code></pre>
  
  <p>If <code>y</code> is null, the statement returns no rows in every case because <code>x = null</code> is always false (should be <code>x IS NULL</code>).
  One solution would be</p>
  
  <pre><code>SELECT * FROM tableA WHERE x = ? OR (x IS NULL AND ? IS NULL)
  </code></pre>
  
  <p>But then i have to set the same parameter twice. Is there a better solution?</p>
  
  <p>Thanks!</p>