user2399158 user2399158 - 2 months ago 12
SQL Question

What causing java.sql.SQLException: Invalid column name on my Update statement?

This is my android SQL statement

I try to update the allergy table, I encounter a lot of problem

stmt1.executeUpdate("UPDATE [dbo].[allergy]
SET [allergy]= "+allergyname+ ",[reaction] = "+reaction+ ",[notes] =" +notes+ " Where patientID ="+patientId);


no matter what I enter into my "allergyname"

It will say Invalid column name

what is happening?

Answer

Your values should be in single quotes. Try below query it will work:

stmt1.executeUpdate("UPDATE [dbo].[allergy] 
SET  [allergy]= '"+allergyname+ "',[reaction] = '"+reaction+ "',[notes] ='" +notes+ "' Where patientID ="+patientId);

Happy coding!!!!!!!!!!