Home > Mobile >  how can I make my sql update statement work?
how can I make my sql update statement work?

Time:06-11

My code won't update the database although I've tried changing every aspect of it to find the mistake please help I can print the set but I can't update and change it. I've tried prepareStatement and createStatement.

public void update() throws SQLException {
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(
            "UPDATE main_table SET status=? WHERE ID=1"
        );
        preparedStatement.setInt(1, 1);
        preparedStatement.executeUpdate();
    }
    catch (SQLException e) {
        System.out.println("Could not update data to the database "   e.getMessage());
    }
}

CodePudding user response:

I would also check your table for any constraints that might be stopping you, and while the code there looks to be functional we're not able to see your database connection.

But here's a working example that should hopefully highlight the cause of your issue

  • Related