title: Db2 .SqlIntegrityConstraintViolationException: SQLCODE=-803, SQLSTATE=23505
body: <p>I am reading from a table in Oracle and inserting the entire dump into Db2.
  The table structures are the same.I am using Simple scala class which does the above mentioned task. I have set the insert batchsize as 300. After a few batches gets updated, the class is throwing the below exception </p>
  
  <pre><code>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]
  </code></pre>
  
  <p>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.
  The constraints on thE Db2 table are</p>
  
  <pre><code> COLUMN NAME                         UNIQUE RULE
      +ID+BUSINESS_STOP+BUSINESS_START    Primary
      +ID                                 Duplicate
      +BUSINESS_START                     Duplicate
      +LOW_QUALITY_IND                    Duplicate
      +IDENTIFIER1                        Duplicate    
      +IDENTIFIER2                        Duplicate
  </code></pre>
  
  <p>I scoured through the other such issues in SO but none of the fixes worked for me.
  The code which is performing this task</p>
  
  <pre><code>    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 =&gt;
        if (sourceConf.hasPath("blockSize")) {
          done = false
        }
  
        //Subtract one to ignore the timestamp field that we are using
        for (idx &lt;- 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 =&gt; {
              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 &gt; 0)  {
        destStmt.executeBatch()
        destDbConn.commit()
        destStmt.clearBatch()
      }
      rs.close()
      stmt.close()
  </code></pre>