Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDBC Transaction Setting

 
Gil Li
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello people..
I wrote a java code to know the transaction process. I clearly set the
AutoCommit into false. Then I forcibly disable the commit just for checking purpose.
But the database changes whenevewr the statement executes. I have given below the code.
It should not update the database .But it does.I dont know where I am missing the technical things..
Please Help me...



import java.sql.*;
import java.util.*;


public class tranc
{
public static void main(String a[])
{
try
{

Class.forName("org.gjt.mm.mysql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/tech?user=root&password=");

con.setAutoCommit(false);


Statement st1=con.createStatement();
st1.executeUpdate("update topic_details set topic='ram' where tid=11");


Statement st2=con.createStatement();
st2.executeUpdate("update topic_details set topic='ram' where tid=9");




if(false)
{
con.commit();
System.out.println("success");
}else
System.out.println("fail");


} catch(Exception e){ e.printStackTrace();}



}
}
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the technical thing you're missing in this case is that most versions of MySQL don't support transactions. If you want transactions, use a proper database. (or read up about how to get or enable transaction support in MySQL)

Jules
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!