Have a connecting (or ref) table with a dual primary key. Have to return the final primary key that was auto produced in the current connection inside a selected table. This really is in java. The database is within MS Access in the event that is important. Sorry for that rushed description, but we is trying to a busy schedule.

Any links or suggestions could be happily appreciated.


The database is populated using SQL. We go into the data for just one form, but we don't be aware of auto produced number. Have to discover what it was so it may be joined in to the ref table. We simply know half the composite key, and that's why we want the 2nd one.


Re the very best answer to date (cant appear to comment). I recieve the next error... "Exception in thread "AWT-EventQueue-" java.lang.UnsupportedOperationException"

Any Advice?

Statement.getGeneratedKeys() should have the desired effect...

You must do a couple of things. First, you will need to pass within an extra parameter when planning your statement or performing your statement. If you are using prepared claims, perform the following:

stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

If you are not using prepared claims, perform the following whenever you call executeUpdate():

stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);

Once you execute your statement, you are able to call

ResultSet rs = stmt.getGeneratedKeys()

This provides you with an effect set that consists of the secrets which were produced.

I've not attempted this method with Access, however it works fine with SQL Server identity posts.

Put both values for that composite key into a range of Object with two elements and return that.

Alternatively, place the new composite type in the instance you simply saved and return that.