0

I am trying to update a MS Access database. I have searched this and I have tried everything I have found but I am still getting the following error.

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

Any help would be very helpful. My code is below...;

    String sqlStatement = "UPDATE ProductCatalogue"
            + "SET [StockLevel] = ?"
            + "WHERE [ProductID] = ?;";

    PreparedStatement prepStatement = connection.prepareStatement(sqlStatement);
    prepStatement.setInt(1, quantity);
    prepStatement.setInt(2, productID);

    //= "UPDATE ProductCatalogue"
    //+ "SET StockLevel = " + quantity
    //+ "WHERE ProductID = " + productID + ";";

    try {
        //myStatement.executeUpdate(sqlStatement);
        prepStatement.executeUpdate();
    } catch (SQLException sqle) {
        System.out.println("Oopss...." + sqle);
    }
    connection.close();
    prepStatement.close();

1 Answer 1

3

you may need a few whitespaces. Try:

String sqlStatement = "UPDATE ProductCatalogue "
            + "SET [StockLevel] = ? "
            + "WHERE [ProductID] = ?;";

(note the space after ProductCatalogue and the first ?)

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.