2014-01-13 20 views
0

當我嘗試在netezza上執行executeBatch()時,會出現錯誤。以下是錯誤:無法在Netezza上執行executeBatch() - JDBC

org.netezza.error.NzSQLException:ERROR:更新已取消:嘗試從多個值更新目標行加入行..

請看看下面的代碼:

String updateDim = "UPDATE DIM_DETAILS set c1 = ? where rep_id = 185 and ar_id = ? and pe_id = ? and se_id = ? and by_id = ?"; 
stmt3 = conn.prepareStatement(updateDim); 

     for (Dim dim : updatedDimList){ 
      upcount += 1; 
      opvalue = BeanUtils.getProperty(dim, dimName.toLowerCase()); 


      stmt3.setString(1, opvalue); 
      stmt3.setString(2, dim.getAr_id()); 
      stmt3.setString(3, dim.getPe_id()); 
      stmt3.setString(4, dim.getSe_id()); 
      stmt3.setString(5, dim.getBy_id()); 
      stmt3.addBatch(); 
      //stmt3.executeUpdate(); 
      //System.out.println("Successfully Updated Rows: "+upcount); 

     } 

     int[] recordsAffected = stmt3.executeBatch(); 

     conn.commit(); 

回答

0

好像你試圖多次更新多行,因爲可能有重複的行。請嘗試刪除這些重複項。

Set<String> keys = new HashSet<String>(); 
//inside the loop 
if(keys.contains(dim.getAr_id() + "#" + dim.getPe_id() + "#" + dim.getCe_id())) 
continue; 
else 
keys.add(dim.getAr_id() + "#" + dim.getPe_id() + "#" + dim.getCe_id());