When I run my query I get this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select last_insert_id() as productid' at line 3
NativeErrorCode number 1064
queryError string :
insert into products (systemname, systemversion, created_date)
values ('web andrea', '', now()); select last_insert_id() as productid;
DatabaseName string MySQL
DatabaseVersion string 5.6.10-log
DriverName string MySQL-AB JDBC Driver
insert into products (systemname, systemversion, created_date) values ('web andrea', '', now()); select last_insert_id() as productid;
I expected the data to get inserted but it fails here.
Thanks in advance
Andrea
You are not running one query but two queries : an
INSERT, then aSELECT.From your application, you would need to make two distinct query calls (one for the insert, the other to get the last inserted id).
Please note that it is likely that your database driver has a built-in function to return the last inserted id (equivalent for
mysqli_insert_idin PHP).