发布时间:2025-11-05 11:31:58 来源:技术快报 作者:IT科技
/*
* Author:spring

* Date :09-03-06 20:28
*/
private PreparedStatement setPreparedStatement(PreparedStatement ps,添加
List pars) throws SQLException {
try {
// 1.获取数组的长度这样能提高一点性能
int x = pars.size();
// 2.循环设置ps中需要的参数
for (int i = 0; i ﹤ x; i++) {
ps.setObject(i + 1, pars.get(i));
System.out.println(pars.get(i));
}
// 3.添加到缓冲区中
ps.addBatch();
// 4.设置完参数的ps返回
return ps;
} finally {
}
}
/
** 执行PreparedStatement泛型列表的云服务器提供商方法
*/
privateboolean exceurePreparedStatement(List﹤PreparedStatement> pss)
throws SQLException {
int x = 0;
try {
// 1.为手动提交
this.conn.setAutoCommit(false);
// 2.执行所有的PreparedStatement对象
x = pss.size();
for (int i = 0; i ﹤ x; i++) {
pss.get(i).executeBatch();
}
// 3.没有错误的话的b2b信息网就提交事务
this.conn.commit();
System.out.println("执行executeBatch()");
// 4.如果提交成功那就返回成功true
returntrue;
} catch (Exception e) {
// 出现异常回滚事务
e.printStackTrace();
System.out.println("执行批量时error");
this.conn.rollback();
//个性化异常
thrownew MyException("page.error.1000","1000 数据执行的批量出错.");
//throw new SQLException();
} finally {
// ***把手动提交改为自动提交
this.conn.setAutoCommit(true);
// 关闭不用的资源
for (int i = 0; i ﹤ x; i++) {
DBUtils.close(pss.get(i));
}
}
}
免费信息发布网随便看看