473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Auto commit data in MySql database using JDBC

58
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....
Sep 18 '07 #1
4 5042
r035198x
13,262 8TB
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();
Sep 18 '07 #2
jith87
58
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?
Sep 18 '07 #3
r035198x
13,262 8TB
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.
Sep 18 '07 #4
r035198x
13,262 8TB
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?
Sep 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mdh | last post by:
I am trying to learn the basics of MVC applications using a Tomcat infrastructure. I'm starting by building a simple application with: * a login.jsp page for a basic login form with a action...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
0
by: sridhar nagabhurshana | last post by:
hello I am trying to connect to mysql database using connector/J jdbc driver this is my code import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;
7
by: Ugrasena via DBMonster.com | last post by:
Hi team i am using DB2 7.2 on Windows2000. We have lot many SQL Procedure Calls, is there any way i can Turn off the Auto Commit on that Database, the Problem i have is many of our Application...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
5
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
4
by: jith87 | last post by:
con = DriverManager.getConnection("jdbc:mysql:///jk","rjk", "sivaji"); con.setAutoCommit(false); java.sql.Statement stmt = con.createStatement(); stmt.executeUpdate("INSERT INTO jk1(fname, lname)...
3
by: Anonymous | last post by:
I resolved this issue. If you are using an Oracle XA DataSource, Oracle's JDBC driver will automatically issue a COMMIT when it sees a "DROP TABLE foobar" statement. Oracle's JDBC driver...
2
by: Zunil | last post by:
Hi All, We are testing one of our component with JDBC + DB2 using db2jcc driver. We afced a strange issue. Scenario is like this. 1. We insert 1 record to a table having IDENTITY column as the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.