IIRC, getLastInsertID() is a wrapper for "SELECT LAST_INSERT_ID()". Thus,
the latter is generally preferrable because you aren't tying your code to a
particular MySQL JDBC driver...
-JF
> -----Original Message-----
> From: Jeff Kilbride [mailto:jeff@stripped]
> Sent: Monday, July 15, 2002 8:45 PM
> To: java@stripped; MHall@stripped
> Subject: Re: returning identity field from a select statement
>
>
> With mm.mysql, you can cast your statement object to an
> "org.gjt.mm.mysql.Statement" and use the "getLastInsertID"
> method. Here's an
> example of how I use this:
>
> long lastInsertID = ((org.gjt.mm.mysql.Statement)stmt).getLastInsertID();
>
> Where stmt is the Statement object you used to execute the insert. You can
> also use the last_insert_id function by executing the following select
> statement, but it has to be on the *same* connection that the insert was
> executed on:
>
> SELECT last_insert_id() AS id;
>
> --jeff
>
> ----- Original Message -----
> From: <MHall@stripped>
> To: <java@stripped>
> Sent: Monday, July 15, 2002 7:28 PM
> Subject: returning identity field from a select statement
>
>
> > MYSQL already has a function mysql_insert_id() for use in the C API but
> > this does not work in java.
> >
> > Is there an equivalent function that I can use in my Java servlet to
> return
> > the identity field after an insert ?
> >
> > I am using the version 1.4 JDK and the version 2.0.14 MM.MYSQL
> JDBC Driver
> > for mySQL .
> >
> > I am using version 3.23.36 of mySQL.
> >
> > Can anyone help ?
> >
> >
> >
> > Michael Hall
> > Email: MHall@stripped
> >
> >
> >
> > ---------------------------------------------------------------------
> > Please check
"http://www.mysql.com/Manual_chapter/manual_toc.html" before
> posting. To request this thread, e-mail java-thread4005@stripped
>
> 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@stripped instead.
>
---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail java-thread4006@stripped
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@stripped instead.