473,394 Members | 1,567 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,394 software developers and data experts.

Auto commit data in MySql database using JDBC

58
Expand|Select|Wrap|Line Numbers
  1. con = DriverManager.getConnection("jdbc:mysql:///jk","rjk", "sivaji");
  2. con.setAutoCommit(false);
  3. java.sql.Statement stmt = con.createStatement();
  4. stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('a', 'b')");
  5. stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('c', 'd')");
  6. con.rollback(); 
  7. stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('x', 'y')");
  8. 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 6027
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....

--------------------------------------------------------------------------------
Please do not double post.
Sep 18 '07 #2
pbmods
5,821 Expert 4TB
Heya, Jith.

Please use CODE tags when posting source code:

[CODE=java]
Java code goes here.
[/CODE]
Sep 18 '07 #3
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. con = DriverManager.getConnection("jdbc:mysql:///jk","rjk", "sivaji");
  2. con.setAutoCommit(false);
  3. java.sql.Statement stmt = con.createStatement();
  4. stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('a', 'b')");
  5. stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('c', 'd')");
  6. con.rollback(); 
  7. stmt.executeUpdate("INSERT INTO jk1(fname, lname) VALUES('x', 'y')");
  8. 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....

--------------------------------------------------------------------------------
Check your table type. You must use the innodb engine:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE  `database_name`.`table_name` (
  2.   `itemID` int(10) unsigned NOT NULL auto_increment,
  3.   PRIMARY KEY  (`itemID`)
  4. ) ENGINE=InnoDB;
Sep 19 '07 #4
r035198x
13,262 8TB
Check your table type. You must use the innodb engine:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE  `database_name`.`table_name` (
  2.   `itemID` int(10) unsigned NOT NULL auto_increment,
  3.   PRIMARY KEY  (`itemID`)
  4. ) ENGINE=InnoDB;
Even then, he creates the connection with the database after setting autoCommit to false. A newly created connection has autoCommit set to true by default so the setAutoCommit(false) at the top there is just useless. He should set autoCommit(false) after creating the connection.
Sep 19 '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...
12
by: Jerry Weinstein | last post by:
Hi, I know about stored procedures and that they can speed up data entry via the SQL 'insert ' statement. However, one drawback to this method is that using the stored procedure still requires...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.