67,513
社区成员
发帖
与我相关
我的任务
分享
Connection conn = abbottDataSource.getConnection();
conn.setAutoCommit(false);
QueryRunner qr = new QueryRunner();
// QueryRunner qr = new QueryRunner(abbottDataSource);
int insertRows = 0;
int updateRows = 0;
try {
insertRows = qr.update(conn, sql);//insert操作
updateRows = qr.update(conn, updateSQL);//update操作
conn.commit();
// result = qr.update(sql);
} catch (Exception e) {
conn.rollback();
throw new Exception("推送MO出错 sql=" + sql, e);
} finally {
conn.setAutoCommit(true);
try {
conn.close();
} catch (Exception e) {
// ignore
}
}
程序中我是这样处理的,也不知道是否正确
begin tran
-- 建立临时表
create table #tmp(id int,A varchar(255),B varchar(255))
-- 插入临时表
insert into #tmp select top 1000 A,B from 表B where C=0
if @@error<>0
begin
rollback tran
return
end
-- 更改已插入数据标记
update 表B set 表B.C = 1 from #tmp where 表B.id = #tmp.id
if @@error<>0
begin
rollback tran
return
end
-- 可以对临时数据进一步处理
-- 转移数据
insert into 表A(A,B) select A,B from #tmp
drop table #tmp
commit tran
手打的 没测试
自己纠一下错