I have to write an API which takes json { mobileno, password and emailId } & returns userId - which is autogenerated in table. My problem is, for this I have to hit the database 2 times, first for insert & then for getting user ID for the given mobileNo. Can it be done with 1 query, ie. how to get auto incremented value of userID
column in return from the insert statement?
My table:
create table signup
(
userid bigint auto_increment primary key,
mobileNo bigint not null,
password VARCHAR_CASESENSITIVE(255) not null,
emailId varchar(320) not null
);
This is the query I am using for inserting the row:
jdbcTemplate.update("insert into SignUP (mobileNo, password, emailId) " + "values(?, ?, ?)", new Object[{signup.getMobileNumber(), signup.getPassword(), signup.getEmail()})