By default, connections start in Auto-Commit mode, which means every statement is executed as a single transaction.

To group several statements in a transaction, you first set autoCommit to false (just like your example); then, execute all the statements you want; and then execute conn.commit() (or conn.rollback() if you detect an error). Since you said everything is working, I assume there is a call to conn.commit() somewhere in your code.

If the call to commit() is being made "too soon", such as after each statement (kind of what happens with autoCommit on), and the host goes down between statements, you have to worry about consistency yourself. Consider a program that withdraws money from one bank account, commits, then deposits into another account, then commits: if the host goes down between commits, some money just disappeared.

On the other hand, if the call to commit() is being made "too late" (only when the user quits the program, for example), then if the host goes down before that, none of the new data will be in the database. It will still be consistent, but data will have been lost.

What you need to do is find out what statements (if any) should be grouped in atomic blocks for your application, then commit() each time one of those blocks finish. 

On Wed, Feb 13, 2013 at 5:28 PM, JimCrowell37 <> wrote:
Bergquist, Brett-2 wrote
> For your use case, probably not.   JPA is not something that is going to
> solve a database element corruption and in fact with JPA and its normal
> use, you have less control when entity changes are flushed to the
> database.
> Note that if you don't have your database stored on medium that has write
> caching, if the host computer goes down, the database is not going to be
> corrupt; it might not have the latest change, but it will be consistent if
> you are using transactions.

My Derby Database is hosted on my HDD in a /db folder under the Java
Application folder...

>" ... if you are using transactions."
The above phrase made me look at my code to see if I am using transactions.
I wrote the derby software some time ago and I have the following lines of
code but I
do not understand why I did the "conn.setAutoCommit(false)" statement...

            //  Control transactions manually...
            //  NOTE:   Auto commit is on by default in JDBC...

Everything is working fine but I wanted to assure myself that the above
operation is OK.

Many Thanks,

View this message in context:
Sent from the Apache Derby Users mailing list archive at