When i have multiple statements in my MySQL query, it is giving me the error: SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server.
Here is my query:
SET @loner_900_id = 1722;
SELECT ds.device_id AS deviceID, dsl.*
FROM devices_statuses AS ds
INNER JOIN devices_statuses_location AS dsl ON ds.id = dsl.device_status_id
WHERE ds.device_id IN (@loner_900_id);
In this query if i remove the SET @loner_900_id = 1722;
and replace the variable @loner_900_id
with the value 1722
, then it works without a problem. But, i would like to run with the "SET @loner_900_id = 1722;"
statement. Please share your thoughts on this.
This is what i do to retrieve the data from the above query. I used JDBC connection.
String url = "jdbc:mysql://<HOST>/test?user=xyz&password=xyz&allowMultiQueries=true";
conn = DriverManager.getConnection(url);
Statement st = conn.createStatement();
conn.createStatement();
resultSet = st.executeQuery(sql);
The error is thrown on the line "resultSet = st.executeQuery(sql);"