• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

is it necessary to set auto commit to true for SELECT

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using JDBC Connection, Statement, Resultset for SQL server.    Do I need to do "connection.setAotiCommit(true)" if the code is just about SELECT a bunch of rows ?  
 
Marshal
Posts: 25831
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's change your question to "Do I have to commit a transaction after running a SELECT statement?" Hopefully you'll agree that's an equivalent statement.

So I searched the web with that question, as one does. I found several web pages about features specific to certain databases. But here's an answer which I found in various forms several times, of which I thought this version was the best:

https://stackoverflow.com/questions/13287749/should-i-commit-after-a-single-select

Note that the answer is neither "Yes" nor is it "No". The answer is "It depends, and here's some things it might depend on".


 
Jack Mutansan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
Paul Clapham
Marshal
Posts: 25831
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have to say, I've never encountered any of those situations where they suggested confirming after doing a SELECT. I've never even encountered a case where I needed to worry about isolation level either.
 
Saloon Keeper
Posts: 22503
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been an ongoing puzzle for me as well. In theory, a SELECT should not need a COMMIT, since a COMMIT is the signal to post changes to the database and a SELECT is read-only.

But in practice, I've had apps give me grief if I didn't COMMIT after I'm done with a SELECT. I suppose that COMMIT could be considered as a signal that the data is no longer needed and buffers can be freed, but in that case. it's really not the best word to describe things.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic