I have the following SQL script (stored in a .sql file) imported into my java program as a string (I changed some variable names so its easier to read):
SET @variable1 := (
//setting the value of this variable here using some values in the database
);
SET @variable2 := (
//setting variable2 with the help of variable1 and some more data
);
SELECT ...
//selecting something using the values of both variables
When I execute this script in MySQL I get the desired result, no errors whatsoever, but I cant do this in JDBC as the script consists of multiple statements. I could execute them as separate statements but they rely on each other (2. statement needs variable1's value to assign variable2's value and so on)
How could I execute this script in JDBC so that I get one ResultSet at the end (which contains the same result as when I execute it in MySQL)? Im essentialy asking how can I "connect" these statements, so that they can use these variables from each other.