Dear All,
I have an application where I got few different sql queries that I would like to have an ACID properties. I have now setAutoCommit false. Where best to put commit and rollback statement?
try
{
[INDENT]dbconn = DriverManager.getConnection("jdbc:mysql://192.168.1.45:3306/***?"+"user=****&password=*****");
dbconn.setAutoCommit(false);
stmt = dbconn.createStatement();
String selectQuery2 = "Select * from tripData Where deviceID="+ intDeviceID +" and dateTimer>'"+dateTimer+"' Order By dateTimer Desc Limit 1";
ResultSet rs2 = stmt.executeQuery(selectQuery2);
//update query
count = stmt.executeUpdate(updateQuery);
//insert query
count = stmt.executeUpdate(insertQuery);[/INDENT]
}
catch (SQLException ex)
{
[INDENT]System.out.println("MyError:Error SQL Exception : "+ex.toString());
ex.printStackTrace(System.out);[/INDENT]
}
finally
{
[INDENT]try
{
if ( stmt != null )
{
stmt.close();
}
else
{
System.out.println("MyError:stmt is null in finally close");
}
}
catch(SQLException ex){
System.out.println("MyError:SQLException has been caught for stmt close");
ex.printStackTrace(System.out);
}
try
{
if ( dbconn != null )
{
dbconn.close();
}
else
{
System.out.println("MyError:dbconn is null in finally close");
}
}
catch(SQLException ex){
System.out.println("MyError:SQLException has been caught for dbconn close");
ex.printStackTrace(System.out);
}[/INDENT]}