db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Waagan <Kristian.Waa...@Sun.COM>
Subject Re: Why derby do not auto commit?
Date Mon, 31 May 2010 07:46:16 GMT
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().


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).

Hope this helps,

[1]  http://db.apache.org/derby/docs/dev/devguide/cdevconcepts29416.html

> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) Client VM (build 16.2-b04, mixed mode, sharing)
> derby 10.6.1 embedded driver
> Code:
>      Connection con =
> DriverManager.getConnection("jdbc:derby:D:/test/testdb");
> //    con.setAutoCommit(true);
>      Statement stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
>      ResultSet rst = stm.executeQuery("SELECT * FROM test_table");
>      rst.moveToInsertRow();
>      rst.updateString(1, "test line");
>      rst.insertRow();
>      rst.beforeFirst();
>      while (rst.next()) {
>        System.out.println(rst.getString(1));
>      }
>      System.out.println(con.getAutoCommit());
> //    con.commit();
>      con.close();

View raw message