我正在从Oracle中的表中读取并将整个转储插入到Db2中。 表结构是相同的。我使用Simple scala类来完成上述任务。我已将insert batchsize设置为300.在几个批次更新后,该类抛出以下异常
com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: Error for batch element #10: DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505, SQLERRMC=1;PME.TM_ASSET_LQA_DETL, DRIVER=4.13.127
at com.ibm.db2.jcc.am.id.a(id.java:673) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.id.a(id.java:60) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.id.a(id.java:127) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.t4.cb.a(cb.java:481) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.t4.cb.a(cb.java:70) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.t4.q.a(q.java:57) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.t4.tb.a(tb.java:225) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.oo.a(oo.java:3434) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.oo.d(oo.java:5550) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.oo.a(oo.java:4992) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.oo.c(oo.java:4664) ~[db2jcc-4.13.127.jar:na]
at com.ibm.db2.jcc.am.oo.executeBatch(oo.java:2934) ~[db2jcc-4.13.127.jar:na]
at com.baml.regw.db.replicator.ReplicationRunnable$$anonfun$run$3.apply(SimpleReplicator.scala:105) ~[regw-db-replicator-0.0.933-SNAPSHOT.jar:na]
at com.baml.regw.db.replicator.ReplicationRunnable$$anonfun$run$3.apply(SimpleReplicator.scala:80) ~[regw-db-replicator-0.0.933-SNAPSHOT.jar:na]
由于异常与IntegrityConstraint有关,我尝试检查是否存在Composite主键(ID + TimeStamp + 9999-12-31 00.00.000000),但组合既不存在于Oracle表中也不存在于Db2表中。 对Db2表的约束是
COLUMN NAME UNIQUE RULE
+ID+BUSINESS_STOP+BUSINESS_START Primary
+ID Duplicate
+BUSINESS_START Duplicate
+LOW_QUALITY_IND Duplicate
+IDENTIFIER1 Duplicate
+IDENTIFIER2 Duplicate
我在SO中搜索了其他类似的问题,但没有一个修复工作对我有用。 执行此任务的代码
logger.info("Retrieving based on query string: " + queryStr + " for thread " + threadNum)
val start = System.currentTimeMillis()
val rs = stmt.executeQuery(queryStr)
val rsMd = rs.getMetaData()
val end = System.currentTimeMillis()
logger.info("Query execution time: " + (end - start) + "ms.")
done = true
var stmtCount = 0
Iterator.continually(rs).takeWhile(_.next()).foreach { rs =>
if (sourceConf.hasPath("blockSize")) {
done = false
}
//Subtract one to ignore the timestamp field that we are using
for (idx <- 1 to (rsMd.getColumnCount()-extraColumnCount)) {
try {
logger.info("destStmt.setObject"+rs.getObject(idx)+" column Type "+ rsMd.getColumnType(idx))
destStmt.setObject(idx, rs.getObject(idx), rsMd.getColumnType(idx))
}
catch {
case e:Exception => {
logger.warn("While attempting to set (1-based) index: " + idx +
" to value of type " + {if(rs.getObject(idx) != null) rs.getObject(idx).getClass().getName() else "[NULL]"} +
" received error: " + e.getMessage())
throw e
}
}
}
destStmt.addBatch()
stmtCount += 1
if(stmtCount % { if (destConf.hasPath("batchSize")) destConf.getInt("batchSize") else 200 } == 0) {
destStmt.executeBatch()
destDbConn.commit()
destStmt.clearBatch()
stmtCount = 0
}
}
if(stmtCount > 0) {
destStmt.executeBatch()
destDbConn.commit()
destStmt.clearBatch()
}
rs.close()
stmt.close()
答案 0 :(得分:0)
检查源数据库(Oracle)中是否存在完全相同的完整性约束。否则,您可能会导入源表中存在的行(因为没有约束),但无法在目标表中导入。
从JDBC 的角度检查两个表(Oracle和DB2)中的列索引是否真的相同。其他工具可以按列名称等排序。更好的是:使用列名称(迭代元数据中的列名称)。如果列被重新排序,如果列被删除并重新添加等,则基于索引的方法将不起作用。例如,如果列中有select * from x
和insert into x values(...)
订单是相关的。
检查源表中的null
值是否属于约束的列。可能Oracle在约束中处理null
值的方式与DB2不同,如果它由索引支持。