user1092042
user1092042

Reputation: 1295

Sql prepared statement not executing

I am using the following code to update my mysql table where both moving50 and moving200 are variable characters.

String sql = "update toplosers set Moving50 = ?, where Symbol = ?";  
PreparedStatement stmt = conn.prepareStatement(sql); 
for(int i1=0;i1<i;i1++)
 {   

       stmt.setString(1, moving50[i1]); 
       stmt.setString(2,symbol[i1]);


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

I am getting "have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where Symbol = 'mysymbol'' at line 1 What is the problem

Upvotes: 0

Views: 472

Answers (3)

Java
Java

Reputation: 2489

No need to add 'comma' for where clause. Now check it.

String sql = "update toplosers set Moving50 = ? where Symbol = ?";  
PreparedStatement stmt = conn.prepareStatement(sql); 
for(int i1=0;i1<i;i1++)
 {   

       stmt.setString(1, moving50[i1]); 
       stmt.setString(2,symbol[i1]);


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

see sample example here

Upvotes: 1

rkosegi
rkosegi

Reputation: 14628

You have unexpected comma right after first parameter.

Upvotes: 2

Marcos
Marcos

Reputation: 4643

Avoid the comma character before the 'where' clause.

Upvotes: 1

Related Questions