title: PreparedStatement with Statement.RETURN_GENERATED_KEYS
body: <p>The only way that some JDBC drivers to return <code>Statement.RETURN_GENERATED_KEYS</code> is to do something of the following:</p>
  
  <pre><code>long key = -1L;
  Statement statement = connection.createStatement();
  statement.executeUpdate(YOUR_SQL_HERE, Statement.RETURN_GENERATED_KEYS);
  ResultSet rs = statement.getGeneratedKeys();
  if (rs != null &amp;&amp; rs.next()) {
      key = rs.getLong(1);
  }
  </code></pre>
  
  <p>Is there a way to do the same with <code>PreparedStatement</code>?</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>The reason I asked if I can do the same with <code>PreparedStatement</code> consider the following scenario:</p>
  
  <pre><code>private static final String SQL_CREATE = 
              "INSERT INTO
              USER(FIRST_NAME, MIDDLE_NAME, LAST_NAME, EMAIL_ADDRESS, DOB) 
              VALUES (?, ?, ?, ?, ?)";
  </code></pre>
  
  <p>In the <code>USER</code> table there's a <code>PRIMARY KEY (USER_ID)</code> which is a <code>BIGINT AUTOINCREMENT</code> (hence why you don't see it in the <code>SQL_CREATE</code> String.</p>
  
  <p>Now, I populate the <code>?</code> using <code>PreparedStatement.setXXXX(index, value)</code>. I want to return <code>ResultSet rs = PreparedStatement.getGeneratedKeys()</code>. How can I achieve this?</p>