I am trying to query the database using the below query. It works fine when I run the query in mysql server. But when I run the same query in scala it throws error.
I want to get a single row in db whose cid_status is "unreserved" and cid_curprocess is 'process1'and update the same cid_status to "reserved" and get back the cid_issueid of that row
Below is the query.
val query = "SET @LastUpdateID := 0; UPDATE table_details INNER JOIN (SELECT cid_issueid FROM cen_issue_details WHERE cid_curprocess='process1' AND cid_status='unreserved' LIMIT 1) AS final ON cen_issue_details.cid_issueid=final.cid_issueid SET cen_issue_details.cid_status ='reserved',cen_issue_details.cid_issueid = (SELECT @LastUpdateID := cen_issue_details.cid_issueid);SELECT @LastUpdateID AS LastUpdateID;
val rs = statement.executeUpdate(query)
I get the below error:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'UPDATE table_details INNER JOIN (SELECT cid_issueid FROM cen_issue_details W' at line 1
Also I am not sure whether to use executeUpdate or executeQuery since the query does both SELECT and UPDATE.