12 messages in com.mysql.lists.javaRe: returning identity field from a s...| From | Sent On | Attachments |
|---|---|---|
| MHa...@ica.com.au | 15 Jul 2002 19:28 | |
| Jeff Kilbride | 15 Jul 2002 20:44 | |
| Mark Matthews | 15 Jul 2002 20:46 | |
| Tim Endres | 15 Jul 2002 20:56 | |
| Steve Forsyth | 15 Jul 2002 20:57 | |
| Javier Bolaños Molina(MCIC) | 15 Jul 2002 23:20 | |
| Andrew Houghton | 16 Jul 2002 09:23 | |
| Steve Forsyth | 16 Jul 2002 11:20 | |
| Mark Matthews | 16 Jul 2002 12:26 | |
| Jon Frisby | 18 Jul 2002 20:12 | |
| Mark Matthews | 18 Jul 2002 20:55 | |
| Jon Frisby | 19 Jul 2002 11:24 |
| Subject: | Re: returning identity field from a select statement![]() |
|---|---|
| From: | Andrew Houghton (aa...@volunteermatch.org) |
| Date: | 07/16/2002 09:23:14 AM |
| List: | com.mysql.lists.java |
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 MHa...@ica.com.au 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: MHa...@ica.com.au
--------------------------------------------------------------------- Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before posting. To request this thread, e-mail java...@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...@lists.mysql.com instead.
--------------------------------------------------------------------- Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before posting. To request this thread, e-mail java...@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...@lists.mysql.com instead.
-- Andrew Houghton aa...@volunteermatch.org




