mysql数据库插入记录时怎么得到刚插入记录的ID
如题,我写了这样的不行,得到的ID是0:
public long saveAndReturnID(String strSQL){
long retID = 0;
Statement stmt = null;
ResultSet rs = null;
try{
stmt = conn.createStatement();
stmt.executeUpdate(strSQL);
org.gjt.mm.mysql.Statement myst = (org.gjt.mm.mysql.Statement) stmt;
retID = myst.getLastInsertID();
myst.close();
stmt.close();
}catch(Throwable e) {
e.printStackTrace();
}finally{
try{
if (null != stmt)
stmt.close();
}catch (Throwable e){
e.printStackTrace();
}
}
return retID;
}