Inserting Rows with Updatable Result Sets

Updatable result sets can be used to insert rows to the table, by using ResultSet.insertRow().

When you insert a row, you must give a value to each column in the new row that does not allow a null value and does not have a default value. If the inserted row satisfies the query predicate, it becomes visible in the result set.

Example of using ResultSet.insertRow() to insert a row:

  Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                        ResultSet.CONCUR_UPDATABLE);
  ResultSet uprs = stmt.executeQuery(
    "SELECT firstname, lastname, workdept, bonus " +
    "FROM employee FOR UPDATE");
  uprs.moveToInsertRow();
  uprs.updateString("FIRSTNAME", "Andreas");
  uprs.updateString("LASTNAME", "Korneliussen");
  uprs.updateInt("WORKDEPT", 123);
  uprs.insertRow();
  uprs.moveToCurrentRow();