Data Store

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
try {
  ...
  connection con.setAutoCommit(false);                    
  PreparedStatement prepStmt = con.prepareStatement(    
    "UPDATE DEPT SET MGRNO=? WHERE DEPTNO=?");            
  prepStmt.setString(1,mgrnum1);                          
  prepStmt.setString(2,deptnum1);
  prepStmt.addBatch();                                   

  prepStmt.setString(1,mgrnum2);                        
  prepStmt.setString(2,deptnum2);
  prepStmt.addBatch();
  int [] numUpdates=prepStmt.executeBatch();              
  for (int i=0; i < numUpdates.length; i++) {             
    if (numUpdates[i] == -2)
      System.out.println("Execution " + i + 
        ": unknown number of rows updated");
    else
      System.out.println("Execution " + i + 
        "successful: " numUpdates[i] + " rows updated");
  }
  con.commit();                                           
} catch(BatchUpdateException b) {
  // process BatchUpdateException
} 

 

Example

posted on 2010-01-06 09:07  standlove  阅读(790)  评论(0)    收藏  举报