I'm executing a script through a Java web service I wrote to execute on a MySQL database. When executing the query in phpMyAdmin it completes successfully, however as soon as it is executed by my web service it returns:
com.mysql.jdbc.exceptions.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 'SELECT @OBJECTIVE_1_DESCRIPTION := OBJECTIVE_DESCRIPTION, @OBJECTIVE_1_LVL := OB' at line 1
The following query is executed as a prepared statement read from a .sql file:
(This is only a snippet of the relevant code, I have added new lines to improve readability, in the actual file the query there are only new lines after each ";")
SET @USER_ID = ?,
@EMAIL = ?,
@NAME = ?,
@SURNAME = ?,
@SUBURB = ?,
@CITY = ?,
@PASSWORD = ?,
@RELIABLE_OCR_RESULTS = 0,
@HOUSEHOLD_SIZE = 0,
@DATE = NOW(),
@OBJECTIVE_1_ID = '4E2DEA7B-037A-4958-8696-2B73EDD3E08E',
@NEW_OBJECTIVE_1_ID = 'E46027A1-CE36-4413-9E64-7A217FFB9CEB',
@OBJECTIVE_1_DESCRIPTION = REPLACE(@OBJECTIVE_1_DESCRIPTION, '*', @OBJECTIVE_1_TARGET),
@OBJECTIVE_1_PROGRESS = 0.0,
@OBJECTIVE_1_COMPLETED = 0,
@COMPLETED_OBJECTIVES = NULL,
@NEW_OBJECTIVE_1_DESCRIPTION = REPLACE(@NEW_OBJECTIVE_1_DESCRIPTION, '*', @NEW_OBJECTIVE_1_TARGET),
@NUM_COMPLETED_OBJECTIVES = 0;
SELECT @OBJECTIVE_1_DESCRIPTION := OBJECTIVE_DESCRIPTION, @OBJECTIVE_1_LVL := OBJECTIVE_LEVEL, @OBJECTIVE_1_TARGET := OBJECTIVE_COMPETION_COUNT, @REWARD_1_CODE := OBJECTIVE_REWARD , @OBJECTIVE_1_REWARD := REWARD_VALUE, @OBJECTIVE_1_REWARD_TYPE := REWARD_TYPE
FROM Objectives
JOIN Objective_Reward_Codes
ON REWARD_ID = OBJECTIVE_REWARD
WHERE OBJECTIVE_ID = @OBJECTIVE_1_ID;
SELECT @NEW_OBJECTIVE_1_DESCRIPTION := Objectives.OBJECTIVE_DESCRIPTION, @NEW_OBJECTIVE_1_LVL := Objectives.OBJECTIVE_LEVEL, @NEW_OBJECTIVE_1_TARGET := Objectives.OBJECTIVE_COMPETION_COUNT, @NEW_REWARD_1_CODE := Objectives.OBJECTIVE_REWARD , @NEW_OBJECTIVE_1_REWARD := Objective_Reward_Codes.REWARD_VALUE, @NEW_OBJECTIVE_1_REWARD_TYPE := Objective_Reward_Codes.REWARD_TYPE
FROM Objectives
JOIN Objective_Reward_Codes
ON Objective_Reward_Codes.REWARD_ID = Objectives.OBJECTIVE_REWARD
WHERE OBJECTIVE_ID = @NEW_OBJECTIVE_1_ID;
DELIMITER ;
Is it possible that it is caused by the version of Tomcat or the encoding of the query sent by the JDBC?