肯定要定义多个preparedStatement。并且要用batch的方式来插入数据
下面是一段相关的代码:
PreparedStatement batchEmps = null;
PreparedStatement batchProdScrap = null;
PreparedStatement batchCutDownScrap = null;
try {
batchEmps = conn.prepareStatement(sqlEmps);
batchProdScrap = conn.prepareStatement(sqlProdScrap);
batchCutDownScrap = conn.prepareStatement(sqlCutDownScrap);
while(){
//根据需要加入数据
............................
} batchEmps.executeBatch();
batchProdScrap.executeBatch();
batchCutDownScrap.executeBatch();
}catch (SQLException ex2) {
println("catch:", ex2);
isOK = false;
}
finally {
try {
if (batchEmps != null) {
batchEmps.close();
}
if (batchProdScrap != null) {
batchProdScrap.close();
}
if (batchCutDownScrap != null) {
batchCutDownScrap.close();
}
}
catch (SQLException ex3) {
println("fianlly:", ex3);
}
return isOK;
}
下面是一段相关的代码:
PreparedStatement batchEmps = null;
PreparedStatement batchProdScrap = null;
PreparedStatement batchCutDownScrap = null;
try {
batchEmps = conn.prepareStatement(sqlEmps);
batchProdScrap = conn.prepareStatement(sqlProdScrap);
batchCutDownScrap = conn.prepareStatement(sqlCutDownScrap);
while(){
//根据需要加入数据
............................
} batchEmps.executeBatch();
batchProdScrap.executeBatch();
batchCutDownScrap.executeBatch();
}catch (SQLException ex2) {
println("catch:", ex2);
isOK = false;
}
finally {
try {
if (batchEmps != null) {
batchEmps.close();
}
if (batchProdScrap != null) {
batchProdScrap.close();
}
if (batchCutDownScrap != null) {
batchCutDownScrap.close();
}
}
catch (SQLException ex3) {
println("fianlly:", ex3);
}
return isOK;
}
batchEmps.setInt(1, activityID);
batchEmps.addBatch();
[Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned
connection while in manual transaction mode.
(1)为了事务处理
(2)connection.commit()有