Execute Multiple SQL Statements

The Simba MongoDB JDBC Driver supports executing multiple SQL statements with a single execute() or executeUpdate() call. The statements must be separated by a semicolon.

For example, to execute multiple statements with a single execute() call:

String sql = "UPDATE test.person SET string='Norton street2' WHERE no='1112';UPDATE test.person SET string='Norton hall' WHERE no='1123'";

statement.execute(sql);

As another example, to execute multiple statements with a single executeUpdate call:

String sql = "UPDATE test.person SET string='Norton street2' WHERE no='1112';UPDATE test.person SET string='Norton hall' WHERE no='1123'";

statement.executeUpdate(sql);

Note:

  • When using executeUpdate(), the first result must be a row count, or else the connector throws an exception. ResultSet type results can be included in the multiple statements as long as the first result is a row count.
  • If an exception is thrown, results and further row count or result sets can still be obtained through the statement.
  • executeUpdate() only returns the update count of the first statement. To obtain row counts for the remaining updates, use getMoreResults().