[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-java
Subject:    Re: id of the created record with insert.
From:       "Christian Mack" <Mack () compal ! de>
Date:       1999-07-15 18:58:50
[Download RAW message or body]

l41484@alfa.ist.utl.pt 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@alfa.ist.utl.pt)               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.


---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail java-thread207@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail java-unsubscribe@lists.mysql.com instead.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic