What's a way/ways to return Identity element (that is auto-generated) in a table from a stored procedure? I have tables in my db with auto generated primary keys that I want to get a hold of when inserting new rows from my Java calling code. I'm trying to create stored procedures that handle the insertion and return back the primary key (ie. the auto-gen key) back to the calling code. I'll only be inserting one row at a time.

I have come across the SCOPE_IDENTITY() function but it seems to not be working inside a stored procedure. I most probably am using it in an incorrect way so that may also be the problem.

Here's what I put together from different sources. This doesn't compile and is in no way a correct way to do it. I'm a newbie, so it may seem like someone trying to communicate in a broken language. Please bear with me.

CREATE OR REPLACE PROCEDURE SAVER(IN PARAMETER1 VARCHAR(30), OUT ID_PARM BIGINT)
BEGIN
DECLARE v_PARAM VARCHAR(30);
DECLARE v_ID BIGINT;
SET v_PARAM=PARAMETER1;
INSERT INTO TAB_1 (NAME) VALUES (v_PARAM);
SELECT SCOPE_IDENTITY() INTO v_ID;
SET ID_PARAM=v_ID;
END


Another thing I'm worried about is I read somewhere that Java and DB2 don't support out parameter so I'm not sure how to return back this value.
The Db2 function to obtain the most recent assigned identity value is IDENTITY_VAL_LOCAL().