Re: javabean to database problem

From: Raffa Edwards <RaffaEdwards3_at_attbi.com>
Date: Sat, 06 Apr 2002 08:09:12 GMT
Message-ID: <H2yr8.222585$702.37074_at_sccrnsc02>


Use the "returning" clause on the insert statement. Unfortunately there's no JDBC api that will handle the returning values. Put the insert statement into a stored procedure and have the output as the returned value.

==> stored procedure fragments
create or replace procedure insReturn (

    stateId      IN number,
           .
           .
    newSkillId     OUT number
) is
    retSkillId      number;

begin

    insert into EDT_SKILL

      values (stateId, ... displayOrder)
      returning edc_skill_id into retSkillId;

    newSkillId := retSkillId;
end insReturn;
/
show errors

==> Java fragments

     String InsStmt = "call insReturn(?, ?, ?, ?, ?, ?, ?, ?)";
     CallableStatement stmt = conn.prepareCall(InsStmt);

     stmt.setLong(1, stateId);
           .
           .
     stmt.setLong(7, displayOrder);
     stmt.registerOutParameter(8, Types.INTEGER);

     stmt.execute();
     returnSkillId = stmt.getLong(8);


"Henry" <hxzhang_at_binary-solutions.net> wrote in message news:aTor8.9737$hS3.500332_at_news0.telusplanet.net...
> I have a table with each row corresponds to a javabean object. The objects
> don't
> necessarily have a primary key, so i use a sequence number as its primary
> key, and a
> trigger to assign the sequence number to its ID column when a new object
 is
> inserted
> into the database.
>
> However, after I insert the object into the table, how can i know the
> object's ID in the
> table? If I simply do a "..._seq.cur_val", it is not safe when multiple
> users can access
> the database and save their javabean into it at the same time.
>
> How could you guys accomplish that?
>
>
Received on Sat Apr 06 2002 - 10:09:12 CEST

Original text of this message