title: JDBC insert or update practice
body: <p>I need to insert a record to table if the record doesn't exist, and to update a record if the record exists in the table.
  Of course, I can write:
  p-code:</p>
  
  <pre><code>SELECT * FROM table1 WHERE id='abc' by JDBC
  if(exists)
     UPDATE table1 SET ... WHERE id='abc' by JDBC;
  else
     INSERT INTO table1... by JDBC;
  </code></pre>
  
  <p>However, I don't think the code is elegant.
  Alternatively, I can also write it in this way:
  p-code:</p>
  
  <pre><code>int row = Statement.executeUpdate("INSERT INTO table1...", 2);
  if(row==0)
    update table1 SET ... WHERE id='abc' by JDBC;
  </code></pre>
  
  <p>Do you think the latter way is better and faster? Thanks!</p>
  
  <p>EDIT: in MYSQL </p>