My database updates just expire after a system restart and are not saved properly

Viewed 37

Good evening! Since this morning, without actually changing anything, I have the problem that when I want to change a value in my database via UPDATE statement, it is not changed in the database.

The funny thing here is that getting the updated value in the next line then also returns the changed value, but after a restart and several phpmyadmin reloads the value still hasn't changed in the database itself.

So somehow UPDATE statement only affect the current execution of the system and not the actual database. Could this be some problem with the caching of my MySQL methods/libraries? If you have any further questions, please feel free to contact me! Thanks in advance! :)

DatabaseHelper.java

   public void editEntry(SearchCondition condition, EditValue... editValues) {
        StringBuilder editCommand = new StringBuilder("UPDATE `" + table.getName() + "` SET ");

        for (int i = 0; i < editValues.length; i++) {
            EditValue editValue = editValues[i];
            editCommand.append("`" + editValue.getColumn() + "` = " + editValue.getValue());
            if (i < editValues.length - 1) {
                editCommand.append(", ");
            }
        }
        editCommand.append(" WHERE ")
                .append("`" + condition.getColumn() + "` = '" + condition.getValue() + "'")
                .append(";");
        System.out.println(editCommand);
        Core.getDatabase().update(editCommand.toString());
    }

    public Object getEntry(SearchCondition... conditions) {
        StringBuilder searchCommand = new StringBuilder("SELECT * FROM `")
                .append(table.getName())
                .append("`");
        if (conditions.length > 0) {
            searchCommand.append(" WHERE ");
            for (int i = 0; i < conditions.length; i++) {
                SearchCondition condition = conditions[i];
                searchCommand.append("`" + condition.getColumn() + "` = \"" + condition.getValue() + "\"");
                if (i < conditions.length - 1) {
                    searchCommand.append(", ");
                }
            }
        }
        try {
            ResultSet resultSet = Core.getDatabase().getResult(searchCommand.toString());
            if (resultSet.next()) {
                return resultSet.getObject(name);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return null;
    }

Main.java

  DataTable.load("stackoverflow").getColumn("id").editEntry(new SearchCondition("name", "justin"), new EditValue("id", 12));
  System.out.println(DataTable.load("stackoverflow").getColumn("id").getEntry(new SearchCondition("name", "justin"));

Output

[System] Started MyExampleProject...
UPDATE `stackoverflow` SET `id` = 12 WHERE `name` = 'justin';
12

Database Value in phpmyadmin before and after execution of the system

26

Disclaimer: Yes, I made sure that the DataTable.load() and getColumn() function work correctly and no caching function was included on my part, but the getEntry() method grabs fresh from the database.

1 Answers

Since the AUTOCOMMIT setting was disabled in MySQL, my changes were not applied to the database when performing an update. But by using .commit() after all necessary changes everything works correctly now! Thanks a lot! :)

Related