I need to be able to insert a row in a parent table and then do multiple inserts into a child table with the parent table’s IDENTITY column value. All these statements are batched together for inserting. I added the following SQL commands, in this order before the “.executeBatch()” command:

DECLARE @parent_table_pk integer;
INSERT into header values (10,’A’);
SET @parent_table_pk = @@IDENTITY;
INSERT into detail (header_id,value1,value2,value3) values (@parent_table_pk,1,1,’A’);
INSERT into detail (header_id,value1,value2,value3) values (@parent_table_pk,2,1,’B’);
INSERT into detail (header_id,value1,value2,value3) values (@parent_table_pk,3,1,’C’);

I get the following SQLException: “Must declare the variable '@parent_table_pk'.”
I would like to not use a trigger or stored procedure to do this. Is there any reason why I can’t use explicit SQL Server commands (that would work from a command window like ‘Query Analyzer’) in JDBC through JDBC ?? How else could I get this to work??