肯定要定义多个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;
    }

解决方案 »

  1.   

    while循环中应该有类似于下面的语句(添加语句到批):
    batchEmps.setInt(1, activityID);
    batchEmps.addBatch();
      

  2.   

    to web_spider:在手动模式(connection.setAutoCommit(false))时,定义多个preparedStatement,Tomcat4.1.18出错:
    [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned
    connection while in manual transaction mode.
      

  3.   

    为什么要用手动模式?最后你有connection.commit()吗?
      

  4.   

    to CoolAbu(绿茶的白开水(★★★★)) :
    (1)为了事务处理
    (2)connection.commit()有