title: Get back the primary key value after insertion to db2 table by KeyHolder
body: <p>Good day,</p>
  
  <p>I have a table in db2, where the primary <code>is_autoincrement</code> is set to <code>Yes</code>. Means that everytime insert data to this table, no need to pass in the primary key value, because it will auto generate.</p>
  
  <p>However, I need to get back the primary key value after insertion. The code is something as follow:</p>
  
  <pre><code>public integer insertRecord() {
  
      //insertion sql code here
  KeyHolder keyHolder = new GeneratedKeyHolder();
  
  PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(
                  getInsertBatch2( ), new int[] { 
                          java.sql.Types.TIMESTAMP, java.sql.Types.VARCHAR,
                          java.sql.Types.SMALLINT, java.sql.Types.DATE,
                          java.sql.Types.INTEGER } );
  
  int updated = JdbcTemplate.update(
                  factory.newPreparedStatementCreator( params ),  keyHolder);
  
  log.trace("key value is " + keyHolder.getKey( );
  
      //after insertion, return primary key
      return id;
  }
  
  private String getInsertBatch2() {
      StringBuilder sb = new StringBuilder( );
      sb.append( "insert into " )
              .append( getDefaultSchema( ) )
              .append(
                      ".batches( startdatetime, type, manual, processdate, originalbatchid) " );
      sb.append( "values(?,?,?,?,?) " );
      return sb.toString( );
  }
  </code></pre>
  
  <p>The insertion query is something as follow:</p>
  
  <pre><code>insert into table1(startdatetime, type, manual, processdate, originalbatchid) value (-- all the value here -- );
  </code></pre>
  
  <p>When I try to print out the keyHolder, it is null. </p>
  
  <p>Kindly advise how to get the primary key.</p>