Domanda

Im getting an error when i try to do an executeBatch() on netezza. Following is the error:

org.netezza.error.NzSQLException: ERROR: Update canceled: attempt to update a target row with values from multiple join rows..

Please take a look at the following code:

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();
È stato utile?

Soluzione

seems like you are trying to update multiple rows multiple times as there might be duplicate rows. Please try to remove such duplicates.

 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());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top