Link to home
Create AccountLog in
Avatar of PurpleSlade
PurpleSlade

asked on

Getting key or variable returned to java program from SQL Server Trigger which inserts to multiple tables

Hi, my problem is this:
We have a java application that sends an INSERT statement to a table.  
The table has a trigger on it which performs multiple INSERTS and UPDATES to multiple tables, one of which is to a PRODUCT table after it creates a new product.
I am interested in retrieving the product_id of the new product from the PRODUCT table.  

After the statement executes, I try and grab the product_id by doing a select statement, but it does not seem that it is available as I am executing the code the first time.  However, it works during the next fire of the application.  

i.e. - String query = "SELECT PRODUCT_ID FROM TABLE WHERE FILE_NAME = 'document." + an + ".pdf'";

works the 2nd time, after the trigger has run, but not the first.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of PurpleSlade
PurpleSlade

ASKER

Both of the answers led me down an educational path.  Although I was not able to find a workable solution, thanks for the ideas.