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
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
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 didn't say it. I'm just telling you what this tiny ad said.