This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes does Connection commit on close()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "does Connection commit on close()?" Watch "does Connection commit on close()?" New topic

does Connection commit on close()?

yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108
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.

If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60774

By default the connection will auto-commit. You can affect this by setting auto-commit to false.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108
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

Joined: Aug 31, 2000
Posts: 108
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.
I agree. Here's the link:
subject: does Connection commit on close()?
Similar Threads
Connection Pooling
SQLException, ResultSet closed but I can figure out why
oracle 9i - commit dependent on driver ?
JDBC-Auto commit
commit - asynchronous or synchronous? (DB2)