Ernestas Gruodis
Ernestas Gruodis

Reputation: 8787

Do we need commit() database connection after query was executed and no changes were made (auto commit is "off")?

Simple question, but.. just want to be sure. If database connection is set to conn.setAutoCommit(false);, after st.executeQuery(...); - do we need to conn.commit();? Of course, if some changes were made like st.execute(...); - conn.commit(); is needed. I'm using HSQLDB.

Upvotes: 4

Views: 1614

Answers (1)

Eran
Eran

Reputation: 393866

In addition to committing updates, commit also releases locks, so it is useful to call commit after executing queries even if no updates were made (though this may be true only for specific databases, and you didn't specify which DB you are using).

Upvotes: 5

Related Questions