B4J Question Mysql LAST_INSERT_ID()

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I am trying to get the LAST_INSERT_ID after an INSERT into a Mysql table.

Code: Copy
dim lastID as INT
gSQL.ExecNonQuery2("INSERT INTO table VALUES (?,?,?,?,?,?)",Array As Object(Null,u(1),u(2),u(3),u(4),Null))
    lastID = gSQL.ExecQuery("LAST_INSERT_ID()")
    Log("Last ID +"&lastID)

I know this code is incorrect but I can't find the correct way of using it in B4j.

Thanks

Any help appreciated.
 
Last edited:
How about

Code: Copy
dim lastID as INT
gSQL.ExecNonQuery2("INSERT INTO table VALUES (?,?,?,?,?,?)",Array As Object(Null,u(1),u(2),u(3),u(4),Null))
    lastID = gSQL.ExecQuerySingleResult("LAST_INSERT_ID()")
    Log("Last ID +"&lastID)
 
Upvote 0
Thanks fixit30

Close but didn't work either.
After a little more research, the correct code is:
Code: Copy
lastID = gSQL.ExecQuerySingleResult("SELECT LAST_INSERT_ID()")
 
Upvote 0
Back
Top