Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

transaction question

 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers
i hope you can help me, probably simple for experts...

i need to change some values in the DB in a transaction.
so i obtain my Connection from the DataSource, set the Connection to autoCommit = false and then obtain Statements/PreparedStatements from this Connection.
after i changed my stuff in the DB i call commit() on the Connection and close the Connection (it probably goes back to the pool since its a pooled DataSource).
here are my questions:
- do i need to set the autoCommit back to true ?
if yes, then i probably need to do it in the "finally" block ?
- what are the transaction levels ?
do i need them to make my transaction working ?
any reading suggestion about this ?
thanks a lot for your help.
k
 
Tina Coleman
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting autocommit: you'll want to set it to whatever it's value was before you changed it. I make that distinction because I don't think that all DBs and drivers have autocommit=true as their default, and you'd want to return the connection to the datasource's pool in the condition it was in before you changed it. And yes, setting autocommit in the finally block is good practice.
Re: transaction-levels: I haven't messed with them - hopefully someone else can give you a better answer.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should assume that someone will take a connection and change it in every possible way. When it is returned to the pool you should reset it so that it will be the same as when it left. It is also a good idea to clear any transactions still associated with the connection by rolling it back.
Jamie
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thanks for replies.
ill take care that i return the Connection in the same state as it was before.
k
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic