java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.

String id= t1.getText();
 int c1=Integer.parseInt(rc1.getText()); /* rc1 is a radiobutton */
 statementobj.executeUpdate("Update tablename(fieldvalue) values('"+c1+"')where ID='"+id+"'");

Recommended Answers

All 3 Replies

I changed the line to

s.executeUpdate("UPDATE emp SET cshift = '+c1+' where ID='"+id+"' ");

Now i got
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

1. Did you tried to execute that statement through MSSQL QueryBrowser or what ever GUI is available for this?
2. You have problem with quotes around parameters inserted into SQL query. '+c1+' should be '"+c1+"' 3. It would be better to start use PreparedStatement as you then do not have to worry with single and double quotes opening and closing. Simple as

String query = "UPDATE emp SET cshift = ? where ID=?";
preparedStatement = conn.prepareStatement(strQuery);
preparedStatement.setString(1,c1);
preparedStatement.setString(2,id);
rs = preparedStatement.executeQuery();

Thank you. Following too works .

s.executeUpdate("UPDATE emp set presence = 'yes' where ID='"+sid+"'");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.