• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

transaction.commit() is this necessary if we didn't do any data manipulation on database?

 
Ryann Ong
Greenhorn
Posts: 19
Fedora Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm just wondering, if do we still need to invoke commit even though we only executed a select query (which means no manipulation will happen on database)?
On the other hand, or is it efficient to call commit without doing any manipulation on database?

Thanks
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A select query does not need a commit.

You can set a connection to auto commit or set method level transactions or some other form of transaction level management to take care of commits
 
Ryann Ong
Greenhorn
Posts: 19
Fedora Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Deepak for your quick response,
 
Ryann Ong
Greenhorn
Posts: 19
Fedora Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another question, sorry i just thought of this, if we don't need to commit.. should we need to begin a transaction?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you do not want a commit you do not need to start a transaction
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:A select query does not need a commit.

You can set a connection to auto commit or set method level transactions or some other form of transaction level management to take care of commits


Largely correct. However, most databases will have to rely on their time out behvaiour to release the resources associated with the transaction if you don't commit or rollback. So if you start one, its a good idea to finish it. Like you said, the best approach for selects is not to use a transaction.
 
Ryann Ong
Greenhorn
Posts: 19
Fedora Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Point taken, plus it will surely reduce the amount of overhead without using transaction in a select query, Thank you for your immediate response guys.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryann,
That's if you really don't have a transaction. Most drivers give you a one statement transaction if you don't already have one.
 
Ryann Ong
Greenhorn
Posts: 19
Fedora Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne, i will check on the driver that i am using if it needs to,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic