title: Prepared Statement syntax for ON DUPLICATE KEY UPDATE (number of params error)
body: <p>Here is what I am trying to do.  I want to insert into this table or update the record if the primary key(entity_id) exists.  I am just having an issue with the SQL syntax.  It wont let me have more params than the first amount of 'VALUES' so I get the following error:</p>
  
  <p>Parameter index out of range (7 > number of parameters, which is 6).</p>
  
  <pre><code>int insertOrUpdateSuccess = MyDBSyncher.UPDATE("INSERT INTO " + DB_NAME + ".entities " +
      "(`entity_id`, `wai_type`, `wai_id`, `character_id`, `looted`, `creation_time`) " +
      "VALUES ((?), (?), (?), (?), (?), (?)) " +
      "ON DUPLICATE KEY UPDATE " +
      "`wai_type`='(?)', `wai_id`='(?)', `character_id`='(?)', `looted`='(?)'", 
      new String[]{tmpEntityId, values[0], values[1], values[2], values[3], values[4],
      values[0], values[1], values[2], values[3]});
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/14089055/pdo-prepared-statements-for-insert-and-on-duplicate-key-update-with-named-placeh">This</a> is kind of similar I think to what I am asking but I could not interpret it for my needs.  Sorry to possibly post a duplicate.</p>
  
  <p>Ohh and here is the UPDATE() function in my code:</p>
  
  <pre><code>public static int UPDATE(String updateStatement, String[] params){
      try {
          if(!conn.isClosed()) {
              logger.trace("Successfully connected to MySQL server using TCP/IP - " + conn);
  
              stat = conn.prepareStatement(updateStatement);
              for (int i = 0; i &lt; params.length; i++){
                  stat.setString(i+1, params[i]);
              }
              return stat.executeUpdate();
          }
      } catch(SQLException eSQL) {
          logger.fatal(eSQL.getMessage());
      }
      return -1;
  }
  </code></pre>
  
  <p>Thanks for any help with this. :)</p>