Connecting Tech Pros Worldwide Forums | Help | Site Map

Auto commit data in MySql database using JDBC

Member
 
Join Date: Jul 2007
Posts: 58
#1: Sep 18 '07
con = DriverManager.getConnection("jdbc:mysql:///jk","rjk", "sivaji");
con.setAutoCommit(false);
java.sql.Statement stmt = con.createStatement();
stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('a', 'b')");
stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('c', 'd')");
con.rollback();
stmt.executeUpdate("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....

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Sep 18 '07

re: Auto commit data in MySql database using JDBC


Quote:

Originally Posted by jith87

con = DriverManager.getConnection("jdbc:mysql:///jk","rjk", "sivaji");
con.setAutoCommit(false);
java.sql.Statement stmt = con.createStatement();
stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('a', 'b')");
stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('c', 'd')");
con.rollback();
stmt.executeUpdate("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
Expand|Select|Wrap|Line Numbers
  1.  con.setAutoCommit(false);
  2. java.sql.Statement stmt = con.createStatement();
Member
 
Join Date: Jul 2007
Posts: 58
#3: Sep 18 '07

re: Auto commit data in MySql database using JDBC


Quote:

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

Expand|Select|Wrap|Line Numbers
  1.  con.setAutoCommit(false);
  2. java.sql.Statement stmt = con.createStatement();


What is meant by code tags?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Sep 18 '07

re: Auto commit data in MySql database using JDBC


Quote:

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.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Sep 18 '07

re: Auto commit data in MySql database using JDBC


Quote:

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?
Reply