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
Author

AutoCommit

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Hi,

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?

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

Be Humble... Be Nice.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
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: http://aspose.com/file-tools
 
subject: AutoCommit
 
Similar Threads
No Transaction
Is SetAutocommit() dangerous?
setAutoCommit(autocommit);
error code when executing BatchUpdate
JDBC transaction concurency