Not to mention that JDBC3.0 / JDK 1.4 has a getGeneratedKeys() method
which will do exactly what you want. Works fine for Statements at the
moment, but seems not to work for PreparedStatements.
- a.
Javier Bolaños Molina(MCIC) wrote:
> 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.
>>
>>
>
>
>
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
> posting. To request this thread, e-mail java-thread4011@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.
>
>
>
--
Andrew Houghton
aah@stripped