-3

I am working on some JSP there I getting data from the connection pool.For getting data I am calling some methods and that each method I have setAutoCommit(true) method. So is there any problem with this method.

Nikolas
  • 2,066
  • 1
  • 19
  • 20
avi
  • 21
  • 3
  • Possible duplicate with: http://stackoverflow.com/questions/10457335/commit-or-conn-setautocommittrue – Milaci Feb 01 '17 at 13:10
  • Don't you think may be my context is another? And also I am java fresher. – avi Feb 01 '17 at 13:13
  • Why would setting a parameter to the same value twice change anything? Should some kind of "super autocommit" be enabled then? – Kayaman Feb 01 '17 at 13:14
  • If the same method is required somewhere then? – avi Feb 01 '17 at 13:17
  • Transactions are no global resource, once returned to the pool they (should) fall back to the pools' settings. Thus invoking autocommit on one tx makes no difference for the next txs' 'user'. Still: Do explicit commit/rollback ;) – Nikolas Feb 01 '17 at 13:25
  • Possible duplicate of [COMMIT OR conn.setAutoCommit(true)](http://stackoverflow.com/questions/10457335/commit-or-conn-setautocommittrue) – Eric Darchis Feb 01 '17 at 13:54

1 Answers1

0

Yea don't do autocommit. Always explicitly commit or rollback your transaction. If anything else it makes your code more readable. The behavior of autocommit=false is vendor specific. So maybe your transactions silently rollback if left uncommited one day and silently commit the other after a major version update.

Nikolas
  • 2,066
  • 1
  • 19
  • 20
  • Thanks for the suggestion. – avi Feb 01 '17 at 13:24
  • Let us say those methods are already there in projects with some intention then? Shall I keep con.commit() or con.setAutoCommit()in my JSP after getting data? – avi Feb 01 '17 at 13:29
  • You always need to remember that once you call one of those methods your transaction _will be commited_ (if they also fire a query that is). So there is no revert / rollback option for you. What if you prepared (incomplete) data before calling the legacy method? You will be forced to call your methods in a very specific order if not to break anything. If other people use your code they might not know about that order. Always make your comprehensible. Your transaction, your responsibility. – Nikolas Feb 01 '17 at 13:46