• Post Reply Bookmark Topic Watch Topic
  • New Topic

SetAutocommit(false)  RSS feed

 
Karthikeyan Pandian
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Even after specifying the Autocommit (false), the insertion in the table is reflected in the database.
Kindly,help me out.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course the change is reflected in the database. But it can be reversed until the database is committed.
 
Karthikeyan Pandian
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cant get you richie.
can you explain it little ellaborately....
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You told the database to execute a command, so it does. It is simply not committed. You inserted "Steve" 22 somewhere. But you have not committed the change.
Commit=false does not mean that the change does not occur.
 
Karthikeyan Pandian
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay,

commit is actually saving the information in the database know??

The information within these brackets getting saved in database(2 , 'Steve') something like this.

but i didnt mention to commit the transaction before closing the connection conn.close().

you know when I open the database after executing the program the changes are reflected in the database as you said , I again closed the oracle database and when the viewed my table the changes

are reflected in the database. I mean the (2,steve) is still there without specifying conn.commit() when I executed my program last time.

My doubt is how to stop the values to get stored in the database when I didnt commit like this conn.commit().


 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You told the database to execute a command, so it does. It is simply not committed. You inserted "Steve" 22 somewhere. But you have not committed the change.

I have to admit that that one mystifies me a little as well. Are you saying that close() automatically issues a commit()? Because that would seem to run directly contrary to what Karthikeyan requested by calling setAutoCommit(false).

When I've used databases in the past - those that allowed it, at least - autocommit=false meant that changes were only visible to you (or your transaction) until they were explicitly committed. A "clean" read might be able to see them, but a dirty read wouldn't; and on many databases they weren't committed to the database (ie, they would be part of a "pending" journal) until an explicit commit. Now I know that Oracle databases tend to do things slightly differently, but it surprises me that simply closing a connection commits a change, particularly when you've explicitly asked the database not to do that.

I should add that I assume that Karthikeyan has tested this by running a separate process after the one he showed us, to prove that the changes were indeed committed.

Winston
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You using Oracle db which from my understanding auto commit on database close. So in your code the data get committed.

Different database behave differently. Yet I can't find the link that support this.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Different database behave differently. Yet I can't find the link that support this.

Connection.close javadoc
It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!