1

I am using the following code to update my mysql database

String sql = "update stocks set price = ?, high = ?, change = ? where SYMBOL = ?";  
PreparedStatement stmt = conn.prepareStatement(sql); 

for(int i=0;i<ing;i++)
 {   

    stmt.setString(1, price[i]); 
    stmt.setString(2, high[i]); 
    stmt.setDouble(3, changedvalue[i]); 
    stmt.setString(4, SYMBOL[i]);

    stmt.addBatch(); 
} 
stmt.executeBatch(); 

where changedvalue is a array of type double. If i remove change it executes properly. But with it it throws the following error.

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 'change = 0.1 where SYMBOL = ''' at line 1 What is the issue

2
  • Why do you have 4 parameters, but you're setting 8? Commented Mar 15, 2012 at 10:20
  • What's the type of change in the database? Commented Mar 15, 2012 at 10:22

2 Answers 2

2

CHANGE is a reserved word in MySQL. Try quoting it:

update stocks set price = ?, high = ?, `change` = ? where SYMBOL = ?
Sign up to request clarification or add additional context in comments.

Comments

0

Your SQL has four parameters. Your code is setting eight. That can't possibly work.

Is this your actual code? If so, that's your problem, and the solution is to make your SQL and code match.

If not, show us your actual code.

3 Comments

Where do you see "setting eight parameters"?
@BartekJablonski: It was before the question was edited. See my comment on the question.
Either that or I started drinking early today.

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.