<p>Is there a cross database platform way to get the primary key of the record you have just inserted?</p>

<p>I noted that <a href="https://stackoverflow.com/questions/165156/easy-mysql-question-regarding-primary-keys-and-an-insert">this answer</a> says that you can get it by Calling <code>SELECT LAST_INSERT_ID()</code> and I think that you can call <code>SELECT @@IDENTITY AS 'Identity';</code> is there a common way to do this accross databases in jdbc?</p>

<p>If not how would you suggest I implement this for a piece of code that could access any of SQL Server, MySQL and Oracle?</p>

Copied from my code:
```
```
pInsertOid = connection.prepareStatement(INSERT_OID_SQL, Statement.RETURN_GENERATED_KEYS);
```
```
where pInsertOid is a prepared statement.
you can then obtain the key:
```
```
// fill in the prepared statement and
pInsertOid.executeUpdate();
ResultSet rs = pInsertOid.getGeneratedKeys();
if (rs.next()) {
  int newId = rs.getInt(1);
  oid.setId(newId);
}
```
```
Hope this gives you a good starting point.