| List: | MySQL and Java | « Previous MessageNext Message » | |
| From: | Mark Matthews | Date: | July 16 2002 3:46am |
| Subject: | Re: returning identity field from a select statement | ||
| View as plain text | |||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
MHall@stripped wrote:
| Mathew
| could you perhaps show me the correct synax to use the function in Java?
Okay, lets say you have an existing Statement named stmt, ready to go.
You just do
ResultSet rs = null;
try {
rs = stmt.executeQuery("SELECT LAST_INSERT_ID()");
long lastInsertId = -1;
if (rs.next()) {
lastInsertId = rs.getLong(1);
}
rs.close();
if (lastInsertId == -1) {
// throw some exception
}
}
finally {
if (rs != null) {
try {
rs.close();
}
catch (SQLException ex ) { /* ignore it */ }
}
}
-Mark
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6-2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE9M5cclyjUJM+7nP4RAnZCAJ9G7/ULfdL2VaIRLxwgYAqYNug7mQCfUPOp
SPXoI/gfx7Yq3Pc7Vl5N+hE=
=cRlv
-----END PGP SIGNATURE-----
| Thread | ||
|---|---|---|
| • returning identity field from a select statement | MHall | 16 Jul |
| • Re: returning identity field from a select statement | Jeff Kilbride | 16 Jul |
| • RE: returning identity field from a select statement | Jon Frisby | 19 Jul |
| • Re: returning identity field from a select statement | Mark Matthews | 19 Jul |
| • RE: returning identity field from a select statement | Jon Frisby | 19 Jul |
| • Re: returning identity field from a select statement | Tim Endres | 16 Jul |
| • Re: returning identity field from a select statement | Javier BolaƱos Molina(MCIC) | 16 Jul |
| • Re: returning identity field from a select statement | Andrew Houghton | 16 Jul |
| • Re: returning identity field from a select statement | Mark Matthews | 16 Jul |
| • Re: returning identity field from a select statement | Steve Forsyth | 16 Jul |
| • Re: returning identity field from a select statement | Steve Forsyth | 16 Jul |
| • Re: returning identity field from a select statement | Mark Matthews | 16 Jul |
