Get last inserted auto increment id in mysql

前端 未结 6 831
你的背包
你的背包 2020-12-09 10:10

I am trying to get the mysql command like mysql_insert_id(); which retrieve the last inserted row\'s auto_increment id. What can I do to get it in Java?

rs =         


        
6条回答
  •  攒了一身酷
    2020-12-09 11:15

    Why not

    SELECT MAX(id) FROM schedule
    

    If id your column has a different name than id, you need to replace it accordingly in the above query.

    You can use it like:

    rs = st.executeQuery("SELECT MAX(id) AS id FROM schedule");
    int lastid = rs.getInt("id");
    

提交回复
热议问题