0

I am trying to update my database when there is a change in the inventory on the client program. The update statement ends up with the correct values in it but i get a mysql syntax error when trying to execute the update.

String sql = "UPDATE video_device SET serialNumber='" + device.getSerialNumber() + "', inventoryNumber=" + device.getInventoryNumber() + ", ownerName='" + device.getServicePerson().getName() 
                    + "', ownerTitle='" + device.getServicePerson().getJobTitle() + "', ownerEmail='" + device.getServicePerson().getEmail() + "', ownerPhoneNumber='" + device.getServicePerson().getPhoneNumber() 
                            + "', dateYear=" + device.getDateAquired().getYear() + ", dateMonth=" + device.getDateAquired().getMonth() + ", dateDay=" + device.getDateAquired().getDay() + ", typeDevice='" + device.getTypeDevice() 
                                   + "', description='" + device.getDescription() + "', price=" + device.getPrice() + ", locationBuilding='" + device.getLocation().getBuilding() + "', locationRoomNumber=" 
                                    + device.getLocation().getRoomNumber() + " WHERE serialNumber='" + orig.getSerialNumber() + "', inventoryNumber=" + orig.getInventoryNumber() + ", ownerName='" + orig.getServicePerson().getName() 
                    + "', ownerTitle='" + orig.getServicePerson().getJobTitle() + "', ownerEmail='" + orig.getServicePerson().getEmail() + "', ownerPhoneNumber='" + orig.getServicePerson().getPhoneNumber() 
                            + "', dateYear=" + orig.getDateAquired().getYear() + ", dateMonth=" + orig.getDateAquired().getMonth() + ", dateDay=" + orig.getDateAquired().getDay() + ", typeDevice='" + orig.getTypeDevice() 
                                   + "', description='" + orig.getDescription() + "', price=" + orig.getPrice() + ", locationBuilding='" + orig.getLocation().getBuilding() + "', locationRoomNumber=" 
                                    + orig.getLocation().getRoomNumber() + ";";
2
  • Why not post the actual error message? Commented Apr 21, 2014 at 1:51
  • 2
    Edit the question and show what sql looks like after the variable substitution. Commented Apr 21, 2014 at 1:51

1 Answer 1

1

It seems like you're separating your WHERE conditions with commas. You have to use AND/OR to separate them.

What it looks like you're doing:

SELECT ...
FROM ...
WHERE a=1, b=2, c=3
etc

What you should be doing:

SELECT ...
FROM ...
WHERE a=1 AND b=2 AND C=3
ETC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.