送高分了!!如何实现对数据库中多个表的操作作为一个transaction处理,达到要么全部提交,要么全部回滚? 和数据库有关希吗?sqlserver2000 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Now I tell you some method:Connection cx = null; public void rollback() { try { cx.rollback(); cx.setAutoCommit(true); } catch (Exception e) { ; } } public void begin() { try { cx.setAutoCommit(false); } catch (Exception e) { sysLog.log(e, "begin"); } } public void commit() { try { cx.commit(); cx.setAutoCommit(true); } catch (Exception e) { sysLog.log(e, "commit"); } }在update table这前用begin();update 出错,就rollback()update 没有出错commit;注意一定是同一个rs.....好运与你同行 看出错提示:你的rs是依赖于stat得到的,而stat初始化是的con并没有被setAutoCommit(false),但是你在对rs操作的过程中执行了setAutoCommit(false),所以出错,试试这个:try{ Connection con; con = DriverManager.getConnection( YOUR_DRIVER,YOUR_DB_NAME,YOUR_DB_PASSWORD ); con.setAutoCommit(false); Statement stat; stat=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs=null; ResultSet rs1=null; rs=stat.executeQuery("select * from table1); rs.moveToInsertRow(); rs.updateInt("Id",1); rs.updateString("Name","aaa"); rs.insertRow(); //出错行 rs1=stat.executeQuery("select * from table2); rs1.moveToInsertRow(); rs1.updateInt("Id",1); rs1.updateString("Name","bbb"); rs1.insertRow(); con.commit();}catch(SQLException sex){ try{ con.rollback(); }catch(Exception ex){}}finally{ try{ con.close(); }catch(Exception ex1){}} awt中Frame的问题,怎样设置弹出窗口与父窗口的关系 请问int转char,有什么函数可以用 怎样用反射机制获得基本数据类型的类型 想学java 一个基础的问题,大家帮帮忙!谢了! 关于ObjectInputStream问题求助 有关jtable问题请教 请问:JAVA 中怎么清空一个char形数组,如:char[] tmp = new char[20]; Applet应用扩展--数字签名(一) 使用签名的jar包,即可实现访问沙箱之外! 求救!!!!!! 请教resin的配置文件resin.conf的问题??? 哪有Oracle8i(for win2000)版下?
Connection cx = null; public void rollback()
{
try
{
cx.rollback();
cx.setAutoCommit(true);
}
catch (Exception e)
{
;
}
}
public void begin()
{
try
{
cx.setAutoCommit(false);
}
catch (Exception e)
{
sysLog.log(e, "begin");
}
}
public void commit()
{
try
{
cx.commit();
cx.setAutoCommit(true);
}
catch (Exception e)
{
sysLog.log(e, "commit");
}
}
在update table这前用begin();
update 出错,就rollback()
update 没有出错commit;
注意一定是同一个rs.....
好运与你同行
你的rs是依赖于stat得到的,而stat初始化是的con并没有被setAutoCommit(false),但是你在对rs操作的过程中执行了setAutoCommit(false),所以出错,试试这个:try{
Connection con;
con = DriverManager.getConnection( YOUR_DRIVER,YOUR_DB_NAME,YOUR_DB_PASSWORD );
con.setAutoCommit(false);
Statement stat;
stat=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=null;
ResultSet rs1=null;
rs=stat.executeQuery("select * from table1);
rs.moveToInsertRow();
rs.updateInt("Id",1);
rs.updateString("Name","aaa");
rs.insertRow(); //出错行
rs1=stat.executeQuery("select * from table2);
rs1.moveToInsertRow();
rs1.updateInt("Id",1);
rs1.updateString("Name","bbb");
rs1.insertRow();
con.commit();
}catch(SQLException sex){
try{
con.rollback();
}catch(Exception ex){}
}finally{
try{
con.close();
}catch(Exception ex1){}
}