I was hoping that I could avoid using a stored procedure, but maybe that's the
only way to get the generated primary key back to the java code in one JDBC
call.
// Dennis
Jay Walters wrote:
> I think it will be returned as an 'out' parameter. If this is true it will
> require you to use the registerOutParameter method to register before
> executing the SQL and then getInt() On the statement after executing the
> statement. This may require a CallableStatement, which is why it doesn't
> quite sound right.
>
> I do what you are asking via a stored procedure call, using an out parameter
> and a callable statement as described above.
>
> You can just check the JDBC docs for Oracle. They are available on their
> website.
>
> Cheers
>
> -----Original Message-----
> From: Dennis Djenfer [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 24, 2001 7:51 PM
> To: [EMAIL PROTECTED]
> Subject: Primary Key Generation
>
> Hi all,
>
> One way to generate a primary key, insert a new row and retrieve the
> generated key in one call is to use the following SQL sentence (at leat
> in a Oracle database)
>
> INSERT INTO emp VALUES (empseq.nextval, 'LEWIS', 'CLARK') RETURNING id
> INTO :bnd1
>
> How do I read the binding variable (:bnd1) that contains my primary key
> (from column "id") from java? Will the binding variable be presented in
> the resultset like:
>
> primaryKey = rs.getInt(bnd1)
>
> or how do I get the value from the Returning clause?
>
> If somebody wonder why I don't test it myself it's because I don't have
> access to a development environment right now
>
> // Dennis
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".