On Mon, 2010-05-31 at 14:43 +0200, Knut Anders Hatlen wrote: > On Mon, 2010-05-31 at 09:46 +0200, Kristian Waagan wrote: > > On 31.05.10 06:03, Hawkx wrote: > > > I found that derby do not auto commit data change on my computer, even I > > > set > > > auto commit to true explicitly. nothing written to database, unless I call > > > commit(). > > > > > > > Hi, > > > > I think this is expected behavior, because you don't close the statement. > > From [1] (* added by me): > > "Auto-commit mode means that when a statement is completed, the method > > /commit/ is called on that statement automatically. Auto-commit in > > effect makes every SQL statement a transaction. The commit occurs when > > the statement completes or the next statement is executed, whichever > > comes first. *In the case of a statement returning a /ResultSet/, the > > statement completes when the last row of the /ResultSet/ has been > > retrieved or the /ResultSet/ has been closed explicitly.*" > > > > When you call close Connection.close(), Derby will do a rollback because > > there is an active transaction (if you had auto-commit set to false, an > > exception would have been thrown). > > I was under the impression that closing the connection would implicitly > close the statement, which would then lead to the transaction being > auto-committed and not rolled back. > > From EmbedConnection's javadoc: > http://db.apache.org/derby/javadoc/engine/org/apache/derby/impl/jdbc/EmbedConnection.html#checkForTransactionInProgress%28%29 > > Check if the transaction is active so that we cannot close down > the connection. If auto-commit is on, the transaction is > committed when the connection is closed, so it is always OK to > close the connection in that case. Otherwise, throw an exception > if a transaction is in progress. >
It turns out this problem is already logged in the bug tracker: https://issues.apache.org/jira/browse/DERBY-3115
