I want to select some rows from my database based on the values stored in my variables (supp_rec array). I have used tips on similar previous post/question. However, I am still having some error messages. The code snippet is below:
waiting_time = dbMngr.runQuery( "SELECT " + "ExpectedWaitingTime" + " FROM Student" + "where deptID = '" + supp_rec[1] + "' and weight = '" + supp_rec[2] + "'");
prob = PoisonModel(Phase3GUI.existence_time - Long.parseLong(waiting_time[0]),2,Phase3GUI.existence_time);
if (prob > 0.5)
{
dbMngr.execUpdate( "DELETE " + " FROM Student" + "where deptID NOT IN" + supp_rec[1] + " and weight NOT IN" + supp_rec[2]);
}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The error message is below:
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 'deptID NOT IN1 and weight NOT IN8' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
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 '= '1' and weight = '8'' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Please I will appreciate any help on how to solve these errors. Thank you.
String.formatfor arbitrary values is a poor way of handling the overall task here.ExpectedWaitingTimein quotes makes it interpret the string letter ally instead of looking at the variable's value. If it isn't a variable, why not just put it all in one string?