mysql在做insert 一条数据后,如何得到这条数据的id

public int insertQuesGrade(QuesGrade quesGrade) {
/** oracle 的一般做法
        int id = baseDAO.getJdbcTemplate().queryForInt("select      SEQ_TBQUESGRADE.nextval from dual");

       Object[] args = {id,quesGrade.getUserid(),quesGrade.getQid(),quesGrade.getWlgid()};
baseDAO.getJdbcTemplate().update("insert into tbquesgrade(qgid,userid,qid,qgtime,wlgid) values(?,?,?,SYSDATE,?)",args);
        return id;
*/


Object[] args = {quesGrade.getUserid(),quesGrade.getQid(),quesGrade.getWlgid()};
baseDAO.getJdbcTemplate().update("insert into tbquesgrade(userid,qid,qgtime,wlgid) values(?,?,SYSDATE(),?)",args);
//在做完insert into后紧接着执行以下查询

            Integer id =  baseDAO.getJdbcTemplate().queryForInt(
"select LAST_INSERT_ID() AS id");
return id.intValue();
}
//今天上午做的周四

Convert.ToDateTime(str)

select * from tbquesgrade;

SELECT @@IDENTITY;

select LAST_INSERT_ID();

select * from tbquesgrade;

insert into tbquesgrade(userid,qid,qgtime,wlgid) values(1,21,SYSDATE(),44451);

你可能感兴趣的:(oracle,mysql)