Inserting rows with updatable result sets

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

When inserting a row, each column in the insert row that does not allow null as a value and does not have a default value must be given a value using the appropriate update method. If the inserted row satisfies the query predicate, it may become 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");
  uprs.moveToInsertRow();
  uprs.updateString("FIRSTNAME", "Andreas");
  uprs.updateString("LASTNAME", "Korneliussen");
  uprs.updateInt("WORKDEPT", 123);
  uprs.insertRow();
  uprs.moveToCurrentRow();