title: Why does getGeneratedKeys() not return any results following an INSERT?
body: <p>I have a table which has one column which is defined as auto-generate-key. When the following code is executed, I expect a new key to be generated but this is not the case. One row is inserted but the ResultSet for <code>ps.getGeneratedKeys()</code> is empty. </p>
  
  <p>I am using DB2: SQLLIB_ADCL_V97FP1.</p>
  
  <pre><code>        conn = getConnection();
          conn.setAutoCommit(false);
          String query = 
              "INSERT INTO MyTable " +
              "  (messe_nr, land5, variable_nr, bezeichnung_en, bezeichnung_de) " +
              "VALUES (?,?,?,?,?)";
  
          PreparedStatement ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
          ps.setInt(1, fair.getFairId());
          ps.setString(2, variable.getCountryCode());
          ps.setInt(3, variable.getSort());
          ps.setString(4, variable.getLabel_en());
          ps.setString(5, variable.getLabel_de());
  
          log.debug(query);
          int count = ps.executeUpdate();
          if(count == 1) {
              ResultSet rs = ps.getGeneratedKeys();
              if(rs.next()) {
                  variable.setId(rs.getBigDecimal(1).intValue());
              } else {
                  log.error("Could not get autogen key after variable insert");
                  throw new AVMSException(1500);
              }
              rs.close();
          }
          log.debug("inserted " + count);
  
          ps.close();
          conn.commit();
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have just deployed the project to the test server and the problem does not occur. Something is broken on my development system - but what? I did install a Java update a day or two back - 1.7.0_13 - could that cause such a problem :-/ ?</p>