1

As we know from here, here and here for a start, calling close on a JDBC connection to Oracle results in a commit although this may not be the case for other JDBC drivers.

I can do a rollback before closing specifically for Oracle, but I was curious whether anybody knows if I can switch this off when opening the connection in a similar way to switching off the auto commit? Thank you.

Community
  • 1
  • 1
nsandersen
  • 896
  • 2
  • 16
  • 41
  • 2
    As the third question/answer you linked states, you should always perform a commit or rollback prior to closing the connection if auto commit is set to false, otherwise the behavior is implementation dependent. – GriffeyDog Mar 04 '14 at 17:11
  • I understand that and have done that - thank you (but it wasn't the question :) ). – nsandersen Mar 05 '14 at 13:50
  • What's the question then? Switch _what_ off? Every transaction must either be committed or rolled back, and in this scenario it is driver-dependent what happens if you don't specifically do one or the other. – GriffeyDog Mar 05 '14 at 14:23
  • Well in my case it should be rolled back. I understand what you mean, thank you (and sorry if it was a cheeky comment to your comment). The question is the headline - I don't see what is wrong about asking that. – nsandersen Mar 15 '14 at 21:18
  • Well, your title implies that you are using the connection with auto-commit on, but you are not. No, you cannot turn off the _behavior_ of some drivers to commit on close (when auto-commit is off), since this behavior is not defined. You need to do a rollback yourself to be safe. – GriffeyDog Mar 17 '14 at 18:25
  • OK, yes, that could be misunderstood - sorry. Well the behaviour of a particular driver might be defined in the driver, but anyway. I think your first comment and your comment just above now answer the question fully, so if I could mark them as answers.. Oh well, you have points enough! – nsandersen Mar 17 '14 at 18:51

1 Answers1

0

You could try subclassing the Connection class and set autoCommit = false in the constructor for example

the1337sauce
  • 539
  • 4
  • 11