I am trying to insert these values into a database, however, the INSERT and WHILE clause are incompatible with each other. Does anybody have any ideas how I could achieve my desired results in a different manner.
public boolean updateAns()
{
boolean success=true;
DBController db=new DBController();
db.setUp("IT Innovation Project");
String sql="INSERT INTO kioskSurveyAns(survey_qn1,survey_qn2,survey_qn3) VALUES('"+radioText+"','"+radioText1+"','"+radioText2+"')SELECT survey_qn1,survey_qn2,survey3 FROM kioskSurveyAns WHERE survey_nric='"+nric+"'";
if (db.updateRequest(sql) == 1)
success = true;
db.terminate();
return success;
}
If you are using
INSERT INTO...SELECTstatement, there should be noVALUESkeyword on it because the value that will be inserted came from theSELECTstatement. egbut looking back on your query, you want to UPDATE the rows based on the values of the controls. right?
As a sidenote, the statement is vulnerable with
SQL Injection. Please do parameterized your query usingPreparedStatements