Close the statement that we use to get the last inserted id.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@333 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-09-28 22:41:40 +00:00
parent 262f10c8c2
commit 3f3edcb0da
@@ -1,5 +1,5 @@
// //
// $Id: MySQLLiaison.java,v 1.3 2001/09/20 20:41:10 mdb Exp $ // $Id: MySQLLiaison.java,v 1.4 2001/09/28 22:41:40 mdb Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -52,13 +52,20 @@ public class MySQLLiaison implements DatabaseLiaison
// documentation inherited // documentation inherited
public int lastInsertedId (Connection conn) throws SQLException public int lastInsertedId (Connection conn) throws SQLException
{ {
Statement stmt = null;
// we have to do this by hand. alas all is not roses. // we have to do this by hand. alas all is not roses.
Statement stmt = conn.createStatement(); try {
ResultSet rs = stmt.executeQuery("select LAST_INSERT_ID()"); stmt = conn.createStatement();
if (rs.next()) { ResultSet rs = stmt.executeQuery("select LAST_INSERT_ID()");
return rs.getInt(1); if (rs.next()) {
} else { return rs.getInt(1);
return -1; } else {
} return -1;
}
} finally {
JDBCUtil.close(stmt);
}
} }
} }