List:MySQL and Java« Previous MessageNext Message »
From:Christian Mack Date:July 15 1999 6:58pm
Subject:Re: id of the created record with insert.
View as plain text  
l41484@stripped wrote:
> 
>  I'm have a little question regarding jdbc & mysql
> 
>  How can i create a record a record using executeUpdate("INSERT INTO ...")
> command and in the same step get the id (an auto increment field) of the
> newly created recorded in the same step?
> 
> Right now i create the record followed by a select to determine the id of
> the newly created record, but this seems like an overkill to me.
> 
> TIA.
> 
> PS. Please respond to me directly since i'm not subscribed to the list.
> 
> --
> Tiago Pascoal  (l41484@stripped)               FAX : +351-1-7273394

Hi Tiago

You have two options:
1) use:
SELECT last_insert_id()
after inserting a new row with auto_increment feature.

2) use the built in feature of your JDBC driver (these are different, so you have to look
for this in their documentation).

Tschau
Christian

PS: Sorry for the late answer, I was on vacation.

Thread
id of the created record with insert. l4148429 Jun
  • Re: id of the created record with insert.Christian Mack15 Jul