Java / SQLite package refinement and auto commit

I copied the following example from the SQLite Java library website:

    PreparedStatement prep = conn.prepareStatement("insert into people values (?, ?);");
    prep.setString(1, "Gandhi");
    prep.setString(2, "politics");
    prep.addBatch();
    prep.setString(1, "Turing");
    prep.setString(2, "computers");
    prep.addBatch();
    conn.setAutoCommit(false);
    prep.executeBatch();
    conn.setAutoCommit(true);

I am trying to understand the meaning of switching autoCommit()on each side executeBatch(). Does this just prevent committing for each individual batch operation? Thus, one “bulk” fixate will be made setAutoCommit(true).

Thank.

+5
source share
2 answers

Auto-commit is disabled before batch loading, since the auto-commit will be enabled (i.e. wait for synchronization, which means that it will wait until the data is actually written to persistent storage, such as a hard drive) after each inserted row.

auto commit false, .

- , ( IO ).

, . , .

, , . , sqlite , .

EDIT:

, , 'on' . / ( ), /. auto-commit true, , . true , /, - /.

Sqlite INSERT.

+8

@havexz , , .

  • FYI, SQLite . setAutoCommit(false) SQLite JDBC- Xerial Zentus. . SO: autocommit sqlite4java?

  • , auto-commit true . , conn.commit();, .

  • , , , .

+3

All Articles