Connection.setAutoCommit() not working with sqlite on iOS?

Hi,

I’m connecting to a sqlite db using jdbc. There seems to be a problem when I use Connection.setAutoCommit(). The following example works fine (psuedo-code, error checking removed, etc):

Connection conn = DriverManager.getConnection(
    "jdbc:sqlite:/path/to/db.sqlite");
PreparedStatement stmt = null;
try {
    stmt = conn.prepareStatement("create table test ...");
    stmt.execute();
    stmt.close();
} finally {
    conn.close();
}

now the same code but using Connection.setAutoCommit():

try {
    conn.setAutoCommit(false);

    stmt = conn.prepareStatement("create table test ...");
    stmt.execute();
    stmt.close();

    conn.setAutoCommit(true);
} finally {
    conn.close();
}

The above doesn’t throw any errors, but the changes are not written to the database file.

The same code works ok on desktop and android - any idea what’s wrong? Maybe it’s some in MOE?

Thank you

Dear bt,

I might be wrong, but when auto commit is false, shouldn’t you call conn.commit() after stmt.execute()?

Best Regards,
Kristóf

Hi, I can try that, but the docs say here:

https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#setAutoCommit(boolean)

NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is committed. If setAutoCommit is called and the auto-commit mode is not changed, the call is a no-op.

Since the auto-commit mode is changed, I guess it should be committed.

Thanks

It says during a transaction.