aspose file tools*
The moose likes JDBC and the fly likes AutoCommit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "AutoCommit" Watch "AutoCommit" New topic


Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627

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: 36452
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
Similar Threads
No Transaction
Is SetAutocommit() dangerous?
error code when executing BatchUpdate
JDBC transaction concurency