title: JDBC getGeneratedKeys()
body: <p>I obtained the following code example from <a href="http://docs.oracle.com/javase/1.4.2/docs/guide/jdbc/getstart/preparedstatement.html" rel="nofollow">http://docs.oracle.com/javase/1.4.2/docs/guide/jdbc/getstart/preparedstatement.html</a></p>
  
  <p>I have three questions:</p>
  
  <ol>
  <li>What does 'keyColumn' refer to considering that there are only three columns - LAST, FIRST, HOME.
  <li>Why is a loop used in iterating the generated keys?  Are multiple rows returned for that one insert statement?
  <li>Which databases support multiple generated keys per table?
  </ol>
  
  <pre><code>String sql = "INSERT INTO AUTHORS (LAST, FIRST, HOME) VALUES " +
                                       "(?, ?, ?, keyColumn)";
  
  PreparedStatement addAuthor = con.prepareStatement(sql,
                               Statement.RETURN_GENERATED_KEYS);
  addAuthor.setString(1, "Wordsworth");
  addAuthor.setString(2, "William");
  addAuthor.setString(3, "England");
  
  int rows = addAuthor.executeUpdate();
  
  ResultSet rs = stmt.getGeneratedKeys();
  if (rs.next()) {
      ResultSetMetaData rsmd = rs.getMetaData();
      int colCount = rsmd.getColumnCount();
      do {
          for (int i = 1; i &lt;= colCount; i++) {
              String key = rs.getString(i);
              System.out.println("key " + i + "is " + key);
          }
      }
      while (rs.next();)
  } 
  else {
      System.out.println("There are no generated keys.");
  }
  </code></pre>