0

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+"'");
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by stephy1
0

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.

0

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();
0

Thank you. Following too works .

s.executeUpdate("UPDATE emp set presence = 'yes' where ID='"+sid+"'");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.