| Author |
transaction.commit() is this necessary if we didn't do any data manipulation on database?
|
Ryann Ong
Greenhorn
Joined: Jan 24, 2010
Posts: 19
|
|
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
Joined: Feb 24, 2006
Posts: 6588
|
|
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
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Ryann Ong
Greenhorn
Joined: Jan 24, 2010
Posts: 19
|
|
|
Thank you Deepak for your quick response,
|
 |
Ryann Ong
Greenhorn
Joined: Jan 24, 2010
Posts: 19
|
|
|
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
Joined: Feb 24, 2006
Posts: 6588
|
|
|
Since you do not want a commit you do not need to start a transaction
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Ryann Ong
Greenhorn
Joined: Jan 24, 2010
Posts: 19
|
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Ryann Ong
Greenhorn
Joined: Jan 24, 2010
Posts: 19
|
|
Thanks Jeanne, i will check on the driver that i am using if it needs to,
|
 |
 |
|
|
subject: transaction.commit() is this necessary if we didn't do any data manipulation on database?
|
|
|