user1092042
user1092042

Reputation: 1295

Updating mysql database using jdbc

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

Upvotes: 1

Views: 541

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1499790

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

update stocks set price = ?, high = ?, `change` = ? where SYMBOL = ?

Upvotes: 2

Tom Anderson
Tom Anderson

Reputation: 47163

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.

Upvotes: 0

Related Questions