• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 19
PHP Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
PHP Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Deepak for your quick response,
 
Ryann Ong
Greenhorn
Posts: 19
PHP Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you do not want a commit you do not need to start a transaction
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
PHP Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
PHP Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeanne, i will check on the driver that i am using if it needs to,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic