Abhishek Singh
Abhishek Singh

Reputation: 9765

OracleJDBC Driver : Does driver commits on close() by default even if conn.setAutoCommit is False?

Does driver commits on close() by default even if conn.setAutoCommit() is set to false?

I have checked it for insert query, and yes it does. Let me know if I'm wrong.

Upvotes: 0

Views: 192

Answers (2)

comeGetSome
comeGetSome

Reputation: 1963

when working with autocommit=false, just do explicitly rollback before closing connection. This way, all updates become reverted unless explicitly committed.

Upvotes: 1

Mark Rotteveel
Mark Rotteveel

Reputation: 109045

When a Connection is closed, it needs to either rollback or commit the current transaction. IIRC, the JDBC specification allows an implementation to choose either as long as it is consistent in its behavior (always commit or always rollback on close). So yes, the behavior is allowed and so it is correct.

If it is the best choice is debatable: you can argue that committing on close makes sure no information is lost, on the other hand you didn't explicitly commit, so maybe you didn't want the info to be persisted.

Upvotes: 2

Related Questions