• 0.16

Updating SQL Records Through JDBC

UPDATE or any other data manipulation queries can be done through JdbcSession:

public class Main {
  public static void main(String[] args) {
    new JdbcSession(source)
      .sql("UPDATE employee SET salary = 35000 WHERE name = ?")
      .set("Jeff Lebowski")
      .update(Outcome.VOID);
  }
}

You can also run a stored procedure (for example, in Oracle):

public class Main {
  public static void main(String[] args) {
    new JdbcSession(source)
      .sql("CALL db.set_salary(?, ?)")
      .set("Jeff Lebowski")
      .set(35000)
      .update(Outcome.VOID);
  }
}

Since version 0.11 you can get a number of updated rows:

public class Main {
  public static void main(String[] args) {
    int updated = new JdbcSession(source)
      .sql("UPDATE employee SET salary = 35000")
      .update(
        new Outcome<Integer>() {
          @Override
          Integer handle(ResultSet rset, Statement stmt) throws SQLException {
            return stmt.getUpdateCount();
          }
        }
      );
  }
}