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.

B4X:
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:

fixit30

Active Member
Licensed User
Longtime User
How about

B4X:
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

atiaust

Active Member
Licensed User
Longtime User
Thanks fixit30

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