• 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

Setting autoCommit Value

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(!conn.getAutoCommit())
conn.setAutoCommit(true);
if(conn != null && !conn.isClosed())
conn.close();

Do we need to explcitly set autocommit to true before closing the connection ? Considering that the connection object is going to be released to the pool, would not having the statement
conn.setAutoCommit(true);
have any undesirable effect ?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if(!conn.getAutoCommit())
conn.setAutoCommit(true);
if(conn != null && !conn.isClosed())
conn.close();


why do you want to set the autocommit to true, though after settin it you are just closing the connection object nothin else.

other thing is, just have a look after accessing the conn object you are checking whether it is null or not. isn't it wiered.

auto commit is ture by default.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess that's a good question.

By default you would assume that AutoCommit was on. I assume that you set it to false earlier in your code to perform a transaction. So, assuming that conn.close() in this case just returns the connection to the pool, rather than actually closing it, if you didn't setAutoCommit(true) it would still be false.

The real question is, what does Pool.getConnection() do? Does it reinitialise the connection before allocating to you or does it just give it to you as it is? Well, obviously good pool code would guarantee the connection in a consistent state, and I think it's fair to assume that. Check the documentation for your peace of mind.

Jules
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,I guess that's a good question,too.but i think the answer to the question depend on the implements of the ConnectionPoolDataSource,maybe.
 
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic