0

We have table called Student with trigger is configured for that, while inserting any row in Student table. Trigger will fire 1 update and 2 insert statements to other tables.

Now we are trying to fetch auto generated ID of Student while inserting. It seems like jdbc resultset is pointing the first update statement (no row to update), because stmt.updateCount() is 0 and while calling stmt.getGeneratedKey() is throwing exception of com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be executed before any results can be obtained.But the student row is inserted into table.

If I disable trigger, I can able to get the Generated ID as expected. Any Idea to get the generated ID of main table while trigger is happening ?
Thanks.

Suseendran P
  • 557
  • 1
  • 5
  • 18
  • I just tried a simple example and `.getGeneratedKeys()` worked fine for me, returning the correct IDENTITY id for the parent table. Please [edit] your question with a [mcve] to show what you are actually doing. – Gord Thompson Jul 26 '19 at 12:27
  • As Gord says, please provide a [mre]. For now I have closed your question to the canonical duplicate. – Mark Rotteveel Jul 26 '19 at 12:49

0 Answers0