It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes AutoCommit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "AutoCommit" Watch "AutoCommit" New topic


Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629

I have a basic question. Every time we write JDBC Code, is it better that we do Connection.setAutoCommit(false); at the beginning and at the end, do, Connection.commit(); Connection.setAutoCommit(true) and close the connection?

[ June 27, 2008: Message edited by: Arjun Reddy ]

Be Humble... Be Nice.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
Yes, but it is probably better still to use a transaction, which does all that sort of thing implicitly. Also a transaction will roll back your database if an error occurs.
Maybe better again to use a stored procedure which embodies a transaction.
I agree. Here's the link:
subject: AutoCommit
It's not a secret anymore!