简体   繁体   English

Db2 .SqlIntegrityConstraintViolationException:SQLCODE = -803,SQLSTATE = 23505

[英]Db2 .SqlIntegrityConstraintViolationException: SQLCODE=-803, SQLSTATE=23505

I am reading from a table in Oracle and inserting the entire dump into Db2. 我正在从Oracle中的表中读取并将整个转储插入到Db2中。 The table structures are the same.I am using Simple scala class which does the above mentioned task. 表结构是相同的。我使用Simple scala类来完成上述任务。 I have set the insert batchsize as 300. After a few batches gets updated, the class is throwing the below exception 我已将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]

Since the exception was related to IntegrityConstraint I tried checking for presence of Composite primary key(ID+TimeStamp+9999-12-31 00.00.000000) but the combo is neither present in the Oracle table nor the Db2 table. 由于异常与IntegrityConstraint有关,我尝试检查是否存在Composite主键(ID + TimeStamp + 9999-12-31 00.00.000000),但组合既不存在于Oracle表中也不存在于Db2表中。 The constraints on thE Db2 table are 对Db2表的约束是

 COLUMN NAME                         UNIQUE RULE
    +ID+BUSINESS_STOP+BUSINESS_START    Primary
    +ID                                 Duplicate
    +BUSINESS_START                     Duplicate
    +LOW_QUALITY_IND                    Duplicate
    +IDENTIFIER1                        Duplicate    
    +IDENTIFIER2                        Duplicate

I scoured through the other such issues in SO but none of the fixes worked for me. 我在SO中搜索了其他类似的问题,但没有一个修复对我有用。 The code which is performing this task 执行此任务的代码

    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()
  • Check if there is really the same integrity constraint in your source database (Oracle). 检查源数据库(Oracle)中是否存在完全相同的完整性约束。 Otherwise you might import rows which exist in your source table (because there isn't a constraint), but which can't be imported in the target table. 否则,您可能会导入源表中存在的行(因为没有约束),但无法在目标表中导入。

  • Check if the column indices are really the same in both tables (Oracle and DB2) from the perspective of JDBC . 从JDBC的角度检查两个表(Oracle和DB2)中的列索引是否真的相同。 Other tools may sort by column name etc. Better yet: Use column names (iterate over the column names in the meta data). 其他工具可以按列名称等排序。更好的是:使用列名称(迭代元数据中的列名称)。 Your index-based approach won't work, if the columns are reordered which possibly happens, if columns are dropped and re-added etc. For example, if you have a select * from x and an insert into x values(...) the column order is relevant. 如果列被重新排序,如果列被删除并重新添加等,则基于索引的方法将不起作用。例如,如果您有一个select * from x和一个insert into x values(...)列顺序是相关的。

  • Check if you have null values in your source table in the columns which are part of the constraint. 检查作为约束一部分的列中的源表中是否包含null值。 Possibly Oracle handles null values in the constraint differently than DB2, if it's backed by an index. 如果由索引支持,Oracle可能会以不同于DB2的方式处理约束中的null值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在获取“ com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException:DB2 SQL错误:SQLCODE = -803,SQLSTATE = 23505 - Im getting "com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505 插入并选择Select Give sql-error(SQLCODE = -803,SQLSTATE = 23505)(db2 z / os) - Insert with Select give sql-error (SQLCODE=-803, SQLSTATE=23505)(db2 z/os) DB2错误SQLCODE = -103,SQLSTATE = 42604 - DB2 Error SQLCODE=-103, SQLSTATE=42604 DB2 jdbc SQL 错误:SQLCODE=-302,SQLSTATE=22001 on Select - DB2 jdbc SQL Error: SQLCODE=-302, SQLSTATE=22001 on Select 对SQL查询(DB2)使用PreparedStatement SQLCODE = -206 SQLSTATE = 42703 - Using a PreparedStatement for a SQL query (DB2) SQLCODE=-206 SQLSTATE=42703 DB2 SQL错误:SQLCODE = -204,SQLSTATE = 42704 - DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704 com.ibm.db2.jcc.am.io:DB2 SQL错误:SQLCODE = -440,SQLSTATE = 42884 - com.ibm.db2.jcc.am.io: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884 准备好的语句失败,并出现DB2 SQL错误:SQLCODE:-401,SQLSTATE:42818 - Prepared Statement failing with DB2 SQL error: SQLCODE: -401, SQLSTATE: 42818 DB2 SQL错误:SQLCODE = -117,SQLSTATE = 42802,SQLERRMC = null,DRIVER = 3.68.61 - DB2 SQL Error: SQLCODE=-117, SQLSTATE=42802, SQLERRMC=null, DRIVER=3.68.61 为什么我使用DB2 LUW和WebSphere App Server获得SQLCODE = -204,SQLSTATE = 42704? - Why do I get SQLCODE=-204, SQLSTATE=42704 with DB2 LUW and WebSphere App Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM