无法在 Netezza 上执行 executeBatch() - JDBC
Posted
技术标签:
【中文标题】无法在 Netezza 上执行 executeBatch() - JDBC【英文标题】:Unable to do a executeBatch() on Netezza - JDBC 【发布时间】:2014-01-13 07:59:47 【问题描述】:当我尝试在 netezza 上执行 executeBatch() 时出现错误。以下是错误:
org.netezza.error.NzSQLException:错误:更新已取消:尝试使用来自多个连接行的值更新目标行..
请看下面的代码:
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();
【问题讨论】:
【参考方案1】:您似乎正在尝试多次更新多行,因为可能存在重复的行。请尝试删除此类重复项。
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());
【讨论】:
以上是关于无法在 Netezza 上执行 executeBatch() - JDBC的主要内容,如果未能解决你的问题,请参考以下文章