title: Prepared statement in if else
body: <p>I'm trying to use prepared statement in if else. Sadly I'm getting Index 1 is out of range.
  Added some details...
  My code:</p>
  
  <pre><code>try {
          String query = "select * from dbo.Table";
          String width = jFormattedTextField1.getText();
          String heigth = jFormattedTextField2.getText();
          PreparedStatement ps;
  
          if (width.equals("") &amp;&amp; heigth.equals("")) {
              query = "select * from dbo.Table ";
          } else if (width != null &amp;&amp; !"".equals(width) &amp;&amp; heigth != null &amp;&amp; !"".equals(heigth)) {
              query += "where width = ? and heigth = ?";
              ps = conn.prepareStatement(query);
              ps.setString(1, width);
              ps.setString(2, heigth);
          } else if (width != null &amp;&amp; heigth.equals("")){
              query += "where width = " + width;
              ps = conn.prepareStatement(query);
          } else {
          query += "where heigth = " + heigth;
          ps = conn.prepareStatement(query);
      }
          ps = conn.prepareStatement(query);
          ResultSet rs = ps.executeQuery();
          jTable1.setModel(DbUtils.resultSetToTableModel(rs));
      } catch (Exception e) {
          JOptionPane.showMessageDialog(null, e, "ERROR", JOptionPane.ERROR_MESSAGE);
      }
  </code></pre>