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 statementMHall16 Jul
  • Re: returning identity field from a select statementJeff Kilbride16 Jul
    • RE: returning identity field from a select statementJon Frisby19 Jul
      • Re: returning identity field from a select statementMark Matthews19 Jul
        • RE: returning identity field from a select statementJon Frisby19 Jul
  • Re: returning identity field from a select statementTim Endres16 Jul
  • Re: returning identity field from a select statementJavier BolaƱos Molina(MCIC)16 Jul
    • Re: returning identity field from a select statementAndrew Houghton16 Jul
Re: returning identity field from a select statementMark Matthews16 Jul
Re: returning identity field from a select statementSteve Forsyth16 Jul
Re: returning identity field from a select statementSteve Forsyth16 Jul
  • Re: returning identity field from a select statementMark Matthews16 Jul