和数据库有关希吗?
sqlserver2000
sqlserver2000
解决方案 »
- 添加和删除数据没有发现LinkedList比ArrayList快
- java的命令行参数是怎么回事?
- 求一个正则表达式
- 哪位大虾能给个处理有效代码的例子(用到正则表达式,I/O流。。 )
- !!!<applet>中的jar怎么设???????!!!!!!!!!!!!!!!!!!
- 怎么让JButton获得焦点
- 大家看thinking in java,有难度吗?
- 大家快来看看,急死我了!在线等待^^^^^^^^^
- 高手请教!如何向oracle中读写二进制文件
- 关于JAVA基础,求教各位大侠(JAVA初学者)
- 请教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){}
}