Skip to main content

autocommit

1. AUTOCOMMIT Function

The AUTOCOMMIT function in H2 database is used to determine whether the auto-commit mode is enabled or disabled for the current connection.

2. Syntax

The syntax for the AUTOCOMMIT function in H2 database is as follows:

AUTOCOMMIT()

Arguments

  • This function does not take any arguments.

Return

  • The AUTOCOMMIT function returns a boolean value indicating whether auto-commit mode is enabled (TRUE) or disabled (FALSE).

3. Notes

  • The auto-commit mode determines whether each SQL statement executed in a transaction is committed immediately or not. When auto-commit is enabled, each statement is committed automatically. When disabled, you need to explicitly commit the transaction using the COMMIT statement.
  • By default, the auto-commit mode is enabled in H2 database.
  • The AUTOCOMMIT function only provides information about the auto-commit mode for the current connection. It does not modify the auto-commit mode.
  • It is important to understand the implications of enabling or disabling auto-commit mode, as it affects the behavior of your database operations.

4. Examples

Here are a few examples demonstrating the usage of the AUTOCOMMIT function in H2 database:

Example 1 - Checking if auto-commit mode is enabled:

SELECT AUTOCOMMIT() AS is_auto_commit_enabled;

Output:

is_auto_commit_enabled
----------------------
TRUE

Example 2 - Checking if auto-commit mode is disabled:

SET AUTOCOMMIT FALSE;

SELECT AUTOCOMMIT() AS is_auto_commit_enabled;

Output:

is_auto_commit_enabled
----------------------
FALSE
  • COMMIT - Commit the current transaction
  • SET AUTOCOMMIT - Enable or disable auto-commit mode