1

I'm trying to call the query:

UPDATE questions 
SET 1 = 4
WHERE questionid = 4;

But I keep receiving an SQL syntax error. I have a column in my table called '1', and I want to set that columns value to the integer 4. I tried some other queries(below), but I still the same error.

UPDATE questions 
SET '1' = 4
WHERE questionid = 4;

UPDATE questions 
SET '1' = 4
WHERE 'questionid' = 4;

UPDATE questions 
SET "1" = 4
WHERE questionid = 4;

UPDATE questions 
SET "1" = 4
WHERE "questionid" = 4;

I'm trying to perform this query in java using the executeUpdate() method from the Statement java API.

I know some of you would advise me using a PerformedStatement rather than a regular Statement for building queries, and I will do, once I can figure out why my query isn't accepting that 1 is a column name and not an integer.

1
  • Try square brackets around the column name, i.e. SET [1] = 4. On a side note, why would you ever name your column that?! Commented Mar 27, 2015 at 19:32

2 Answers 2

2

Use backticks arround the column name:

UPDATE questions 
SET `1` = 4
WHERE questionid = 4;

Think about renaming your column.

Sign up to request clarification or add additional context in comments.

1 Comment

ah I knew it was something really basic, thanks alot :D
1

Try the following:

UPDATE questions
SET [1] = 2 -- int
WHERE QuestionID = 1;

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.