title: How to perform an update query in Java?
body: <p>I am not so into database and I have the following problem in a Java application that have to perform a very simple query that update a field on a table of my DB.</p>
  
  <p>So, the original query is something like this:</p>
  
  <pre><code>UPDATE coda_tx c SET c.FK_STATO = 2 WHERE c.PK_CODA = 62816; 
  </code></pre>
  
  <p>so I have implemented the following Java method that implement the previous query, this one:</p>
  
  <pre><code>public void updateStatus(int pkCoda, int newStatus) {
  
      String sql;
  
      StringBuffer sb = new StringBuffer();
  
      sb.append("UPDATE coda_tx c SET c.FK_STATO = ");
      sb.append(newStatus);
      sb.append(" WHERE c.PK_CODA = ");
      sb.append(pkCoda);
  
      sql = sb.toString();
  
  
      try {
          statment = connection.createStatement();
          ResultSet rs = statment.executeQuery(sql);
      } catch (SQLException e) {
          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
  }
  </code></pre>
  
  <p>My only doubt is related about the section by which the query is performed, this one:</p>
  
  <pre><code>statment = connection.createStatement();
  ResultSet rs = statment.executeQuery(sql);
  </code></pre>
  
  <p>I think that this is wrong because actually there is <strong>ResultSet</strong> that is an object used to retrieve rows by a <strong>SELECT</strong> operation. In this case I am updating a field of a specific row and I am not retrieving rows putting theme into a <strong>ResultSet</strong> object.</p>
  
  <p>So, how can I correctly handle this situation? How have I to perform my query?</p>