Auto commit data in MySql database using JDBC

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jith87
    New Member
    • Jul 2007
    • 58

    Auto commit data in MySql database using JDBC

    con = DriverManager.g etConnection("j dbc:mysql:///jk","rjk", "sivaji");
    con.setAutoComm it(false);
    java.sql.Statem ent stmt = con.createState ment();
    stmt.executeUpd ate("INSERT INTO jk1(fname, lname) VALUES('a', 'b')");
    stmt.executeUpd ate("INSERT INTO jk1(fname, lname) VALUES('c', 'd')");
    con.rollback();
    stmt.executeUpd ate("INSERT INTO jk1(fname, lname) VALUES('x', 'y')");
    con.commit();

    By ths code the records containing values a,b and c,d should nt be saved bt the record containing x,y should be saved...bt all the three records r getting saved...Pls help....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by jith87
    con = DriverManager.g etConnection("j dbc:mysql:///jk","rjk", "sivaji");
    con.setAutoComm it(false);
    java.sql.Statem ent stmt = con.createState ment();
    stmt.executeUpd ate("INSERT INTO jk1(fname, lname) VALUES('a', 'b')");
    stmt.executeUpd ate("INSERT INTO jk1(fname, lname) VALUES('c', 'd')");
    con.rollback();
    stmt.executeUpd ate("INSERT INTO jk1(fname, lname) VALUES('x', 'y')");
    con.commit();

    By ths code the records containing values a,b and c,d should nt be saved bt the record containing x,y should be saved...bt all the three records r getting saved...Pls help....
    1.) Use code tags when posting code
    2.)By default all new connections are created in autocommit mode. You set the flag before creating the connection.
    Interchange these two statements
    [CODE=java] con.setAutoComm it(false);
    java.sql.Statem ent stmt = con.createState ment();[/CODE]

    Comment

    • jith87
      New Member
      • Jul 2007
      • 58

      #3
      Originally posted by r035198x
      1.) Use code tags when posting code
      2.)By default all new connections are created in autocommit mode. You set the flag before creating the connection.
      Interchange these two statements
      [CODE=java] con.setAutoComm it(false);
      java.sql.Statem ent stmt = con.createState ment();[/CODE]

      What is meant by code tags?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by jith87
        What is meant by code tags?
        Compare how you posted your code and and how I posted it in the posts above. Code tags make it easier to read that code that you post in the forum.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by r035198x
          Compare how you posted your code and and how I posted it in the posts above. Code tags make it easier to read that code that you post in the forum.
          Now jith87, please stop all this double posting for the same question. That is simply against the site guidelines and I hope I won't have to warn you about it again. Did you read the response that I posted for this question?

          Comment

          Working...