Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does Connection commit on close()?

 
yogesh sood
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried searching on google about the fact that when we close connection whether it gets commited in database itself.

I was unable to locate any mention of this on Java Doc API. So i think it is a moot point and may be left to implementation. I noticed in DB2 it does so , which means that it commit if i close connection.

I did some search on oracle 8i, it seeems like there is also some confusion about the same in Oracle implementation.

It would be nice if anyone can provide some inputs here.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default the connection will auto-commit. You can affect this by setting auto-commit to false.
 
yogesh sood
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologies for not mentioning detail of auto commit flag. I m referring to scenario where I have set the auto commit to false and im running one transaction and instead of commit and rollback at teh end of transaction, if i close()connection what will be the behavior? Is it going to implementation specific?
 
yogesh sood
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got answer , if i set autocommit to false and then try to close connection withour performing commit or rollback then it is a invalid state for JDBC and it throws invalid transaction state.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic