title: JDBC How to update a database?
body: <p>I'm studying for the OCPJP certification, and actually I'm in the JDBC chapter. I understood that I can update a database in two ways: 1st one is using the JDBC APIs, in particular the updatexxx methods in the ResultSet class; 2nd one is sending a Statement via the execute method so that the DBMS will execute the update itself. So, suppose I have a table named "contacts" and I want to update the "phoneNo" field to "1234567890" where the "name" field is equal to "George". Note that I'm using MySQL. What are the differences, if any, between this</p>
  
  <pre><code>ResultSet resultset = statement.executeQuery("SELECT * FROM contacts WHERE name=\"George\"");
  resultset.updateString("phoneNo", "1234567890");
  updateRow();
  </code></pre>
  
  <p>and this?</p>
  
  <pre><code>statement.executeUpdate("UPDATE contacts SET phoneNo=\"1234567890\" WHERE name=\"George\"");
  </code></pre>
  
  <p>When should I use the 1st method and when the 2nd one? Why should I prefer one of them on the other?
  Thank you :D</p>