jdbc autocommit(false) doesnt work

Viewed 5046

There is something i don't understand with java.sql.Connection.commit().

I am using Derby(Java DB) as database server.

when I do a setAutoCommit(false) , I expect my query not to work before I explicitly call the commit() method. but in fact, it still commit even if I don't call commit(). when I call a select * on my table to print the content, I can see that the rows have been added even though i didn't explicitly commit the query.

Could someone give me some explanation please?

    con.setAutoCommit(false);
    PreparedStatement updateHair = null;
    PreparedStatement addMan = null;
    try {

         String updateString =
                    "update PERSONNE " +
                    "set haircolor = 'RED' where haircolor = 'SHAVE'";

         String updateStatement =
                    "insert into personne values " +
                    "(3,'MICHEL','SHAVE')";

         addMan = con.prepareStatement(updateStatement);
         addMan.executeUpdate();

         updateHair = con.prepareStatement(updateString);
         updateHair.executeUpdate();

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
1 Answers
Related