File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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: 41091
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