File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Database Autocommit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Autocommit" Watch "Database Autocommit" New topic
Author

Database Autocommit

Tom Keith
Greenhorn

Joined: Mar 26, 2002
Posts: 24
Hi All,
I have a question regarding database autocommit. It might sound silly. But I just want to clear my doubts.
Consider the following scenarios:
Question 1
-----------
1) Some DML statments followed by some DDL statements (just for argument sake) and no autocommit defined in the java program, How is the transaction commited?
2) Some DML statments and no autocommit defined in the java program, How is the transaction commited?
Question 2
----------
If no commit is specified in the java program, the which one does the commit:
Is it the JDBC driver that prompts the dadabase to commit the transaction (if so does all the JDBC drivers have this property by default?) or does the Datbase does it by itself?
Thanks,
Tom
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
Regarding question 2 it depends on the database. Sybase for example has auto-commit mode as true by default. To check the current auto-commit state, you can use method getAutoCommit() of Connection interface. commit() method of Connection makes all changes since the previous rollback/commit permanent.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Assuming Autocommit is set to false:
In case 1
As soon as you execute a DDL statement, before anything happens, a commit is implicitly called by the database ( this also happens when you are working in a SQL session ). No matter what you have set autocommit to, the commit takes place just before the DDL is executed.
In case 2
It can be driver specific/database specific, but in general if the driver supports transactions, then the DML statements will not be committed and the transaction will be rolled back. Try a test case to verify it or read through your jdbc driver documentation.
Assuming Autocommit is set to true:
after each executeUpdate() a commit takes place
As stated above, the default for autocommit() varies from driver to driver.
Jamie
[ August 30, 2002: Message edited by: Jamie Robertson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Autocommit