// 数据事务处理操作
public static boolean TransactionOp(String[] strSql){
try
{
con.setAutoCommit(false);
Statement stm = con.createStatement();
int i=strSql.length;
for(int j=0;j<i;j++)
{
stm.executeUpdate(strSql[j]);
} con.commit();
con.setAutoCommit(true);
return true;
}
catch(Exception e)
{
try
{
con.rollback();
con.setAutoCommit(true);
e.printStackTrace();
return false;
}
catch(Exception e1)
{
return false;
}
}
}执行一组SQL语句回滚了,可是单独执行这些SQL语句是没有问题的,这是为什么?
public static boolean TransactionOp(String[] strSql){
try
{
con.setAutoCommit(false);
Statement stm = con.createStatement();
int i=strSql.length;
for(int j=0;j<i;j++)
{
stm.executeUpdate(strSql[j]);
} con.commit();
con.setAutoCommit(true);
return true;
}
catch(Exception e)
{
try
{
con.rollback();
con.setAutoCommit(true);
e.printStackTrace();
return false;
}
catch(Exception e1)
{
return false;
}
}
}执行一组SQL语句回滚了,可是单独执行这些SQL语句是没有问题的,这是为什么?
如果不清楚可以先试1,2SQL语句一起,然后1,2,3。