Re: javabean to database problem

From: crappy <crappygolucky_at_hotmail.com>
Date: 8 Apr 2002 06:42:45 -0700
Message-ID: <ce31c410.0204080542.37871dfd_at_posting.google.com>


actually i think you can use the returning clause with an anonymous pl/sql block ..

    CallableStatement stmt = conn.prepareCall(

        "begin insert into thetable (col1, col2, col3) values (5555, 'blah', 11) returning edc_skill_id into ?; end;");

    stmt.registerOutParameter(1, Types.INTEGER);     stmt.execute();
    int newID = stmt.getInt(1);

"Raffa Edwards" <RaffaEdwards3_at_attbi.com> wrote in message news:<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 Mon Apr 08 2002 - 15:42:45 CEST

Original text of this message