gushax
gushax

Reputation: 3

Update Statement - Syntax error in UPDATE statement (Java & MS Access)

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

Upvotes: 0

Views: 1221

Answers (1)

Paolo Falabella
Paolo Falabella

Reputation: 25844

you may need a few whitespaces. Try:

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

(note the space after ProductCatalogue and the first ?)

Upvotes: 3

Related Questions