title: PreparedStatement.RETURN_GENERATED_KEYS and Mysql
body: <p>I am trying to fix this code to update my log table in a mysql database 5.6
  Do you know how to retrieve the primary key from the database and assign it to my id variable (Log)</p>
  
  <p>Thanks</p>
  
  <p>Log model without getters and setters</p>
  
  <pre><code>private int id;
  private Timestamp date;
  private String userName;
  private String event;
  private String message;
  private String audioPath;
  </code></pre>
  
  <p>Database Table</p>
  
  <pre><code>CREATE TABLE `log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `date` datetime(2) NOT NULL DEFAULT '0000-00-00 00:00:00.00',
  `user_name` char(60) NOT NULL,
  `event` varchar(50) NOT NULL,
  `message` text NOT NULL,
  `audio_path` varchar(250) NULL,
   PRIMARY KEY (`id`)
  )ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>Add Entry Log</p>
  
  <pre><code>@Override
  public int addEntry(Log log) throws SQLException {
  
      Connection conn = Database.getInstance().getConnection();
  
      PreparedStatement p = conn.prepareStatement(
              "insert into log ( id, date, user_name, event, message, audio_path) "
              + "values (?,?,?,?,?,?)", 
              PreparedStatement.RETURN_GENERATED_KEYS);
  
      p.setInt(1, p.getGeneratedKeys()); //error
      p.setTimestamp(2, log.getDate());
      p.setString(3, log.getUserName());
      p.setString(4, log.getEvent());
      p.setString(5, log.getMessage());
      p.setString(6, log.getAudioPath());
  
      int updated = p.executeUpdate();
  
  
      p.close();
  
      return updated;
  
  }
  </code></pre>