I don't know a function that does this but if you take this steps you will
have the same result
PreparedStatement stmtInsertSomething =
conn.prepareStatement("INSERT INTO sometable (autoincrement_id,
other_field) VALUES ('', ?);
stmtInsertSomething.setInt(1, somevalue);
stmtInsertSomething.executeUpdate();
PreparedStatement stmtGetLastID = conn.prepareStatement("SELECT
LAST_INSERT_ID()");
ResultSet rs = stmtGetLastID.executeQuery();
rs.next();
int lastID = rs.getInt(1);
that's all.
Good luck!
On Tue, 16 Jul 2002 MHall@stripped wrote:
> 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.
>
>