title: Can you tell me why I get "Can't use query methods that take a query string on a PreparedStatement."?
body: <p>I keep hitting an error "Can't use query methods that take a query string on a PreparedStatement." when trying to debug the following code &amp; SQL Select query. (Postgres 9.4, jdk 1.8)  Maybe I'm blind and it's a simple type, but I could use some help.</p>
  
  <p>My Console Ouput:  </p>
  
  <blockquote>
    <p>SELECT rowid, firstname, lastname, prefname, email1, email2, email3, type, status, preflang, mbrappid, deviceid, mbrstatus, mbrtype, mbrcat, pr_phonevoice FROM qbirt.person WHERE pr_sms = 47 ORDER BY lastupdt DESC</p>
    
    <p>E R R O R 
    JDBC Prep'd Stmt error on Primary Phone FKey...
    Phone FKey: 47  </p>
    
    <p>SQLException: Can't use query methods that take a query string on a PreparedStatement. 
    SQLState: 42809 
    VendorError: 0 
    org.postgresql.util.PSQLException: Can't use query methods that take a query string on a PreparedStatement.
        at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:102) at solutions.demand.qbirt.Person.findMember(Person.java:762)`</p>
  </blockquote>
  
  <p>Portion of code:</p>
  
  <pre><code>            if (!foundMbr &amp;&amp; foundPhoneID &gt; 0) {
                  if (QbirtUtils.verbose) {
                      System.out.println("Querying Person by FK ID for phones: " + foundPhoneID + "\n");
                  }
  
                  if (mode.equals(pMode.SMS)) {
                      qry = "SELECT rowid, firstname, lastname, prefname, email1, email2, email3, type, "
                              + "status, preflang, mbrappid, deviceid, mbrstatus, mbrtype, mbrcat, pr_phonevoice "
                              + "FROM qbirt.person "
                              + "WHERE pr_sms = ? "
                              + "ORDER BY lastupdt DESC;";
                  } else {
                      if (mode.equals(pMode.VOICE)) {
                          qry = "SELECT rowid, firstname, lastname, prefname, email1, email2, email3, type, "
                                  + "status, preflang, mbrappid, deviceid, mbrstatus, mbrtype, mbrcat, pr_phonevoice "
                                  + "FROM qbirt.person "
                                  + "WHERE pr_phonevoice = ? "
                                  + "ORDER BY lastupdt DESC;";
                      } else { 
                          if (mode.equals(pMode.PHONE)) {
                              qry = "SELECT DISTINCT ON (rowid) rowid, firstname, lastname, prefname, email1, email2, email3, type, "
                                      + "status, preflang, mbrappid, deviceid, mbrstatus, mbrtype, mbrcat, pr_phonevoice "
                                      + "FROM qbirt.person "
                                      + "WHERE (pr_sms = ? OR pr_phonevoice = ?) "
                                      + "ORDER BY lastupdt DESC, rowid DESC;";
                          }
                      }
                  }
  
  
  
                  try {
                      PreparedStatement pStmt = conn.prepareStatement(qry);
                      pStmt.setInt(1, foundPhoneID);
                      if (mode.equals(pMode.PHONE)) {
                          pStmt.setInt(2, foundPhoneID);
                      }
                      System.out.println(pStmt.toString());
                      ResultSet rs = pStmt.executeQuery(qry);   &lt;-------
  </code></pre>
  
  <p>I have confirmed that the fields contain the following values:<br>
  <code>foundMbr</code> = false, <code>foundPhoneID</code> = 47, <code>mode</code> = SMS, and that  <code>qry = "SELECT rowid, firstname, lastname, prefname, email1, email2, email3, type, status, preflang, mbrappid, deviceid, mbrstatus, mbrtype, mbrcat, pr_phonevoice FROM qbirt.person WHERE pr_sms = ? ORDER BY lastupdt DESC;";</code></p>
  
  <p>I get the error on the line:  <code>ResultSet rs = pStmt.executeQuery(qry);</code></p>
  
  <p>As you can see in the console, I have even confirmed that the pStmt is holding the correct binding because I print it out.  - That said, it seems to be missing the ending ';'.  Not sure why that is because I can see it in the qry string.  I assume that is just a quirk of the preparedStatment.</p>
  
  <p>I have also copied this exact SQL into pgAdmin III and successfully executed it manually.   Although, I did have to add back the ';'.  I use virtually this same code in many other areas without problem.</p>
  
  <p>Could it be that the missing ';'?<br>
  Maybe some sort of type mismatch?  (foundPhoneID is an int., rowid is a serial/integer, pr_sms is an integer FKey)<br>
  Could it be the block of if statements that defines the qry string?</p>
  
  <p>TIA!</p>