Sigh
Sigh

Reputation: 133

Update statement working in SQLite Browser not in java with the exact same syntax

Okay I executed the same code thats in the update query in the SQLite db browser and it worked successfully

public void StatusUpdate(ActionEvent event) {   

    try {

        String test = null;
        test = txtEditStatus.getText();
        System.out.println(test);

        String query = "UPDATE member SET desc = ? WHERE username = ?";
          PreparedStatement preparedStmt = connection.prepareStatement(query);
          preparedStmt.setString   (1, test);
          preparedStmt.setString(2, "Custom Hue");

          // execute the java preparedstatement
          preparedStmt.executeUpdate();

          connection.close();



    } catch (Exception e) {

    }

However when running eclipse with JFx, it prints what I type in the console but doesnt update in the db, anyone know why?

For the user asking about the connection:

Connection connection;

public ProfileController() {
    connection = SQLConnection.Connector();
    if (connection == null)
        System.exit(1);
}

Upvotes: 0

Views: 51

Answers (1)

Morten Bork
Morten Bork

Reputation: 1632

I would check that your connection is actually connected to the correct database. are you sure you have the right connection string set up?

you should do an output on your exception handler, what if there is an exception?

are you sure the connection is open? are you sure the user exists in the database and table you are trying to update? try doing a read first, to see if you have an open connection. Print your exception, just in case, never leave it blank. That's just bad practice.

How about you try a

  preparedStmt.executeUpdate();
  connection.commit(); 
  connection.close();

Just incase autocommit isn't enabled?

Upvotes: 1

Related Questions