• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Database Autocommit

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic