SQL - Not deleting properly

Discussion in 'Plugin Development' started by will181, Oct 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    will181

    Hey, I am creating a plugin that uses an SQL database to store the player's points. Everything is working fine except this one method:

    Code:java
    1.  
    2. public static void addPoints(UUID p, int points) {
    3. try {
    4. if(!db.checkConnection())
    5. db.openConnection();
    6.  
    7. int currentPoints = getPoints(p);
    8.  
    9. PreparedStatement preparedStatement = db.getConnection().prepareStatement("DELETE FROM 'points' WHERE 'UUID'=?;");
    10. preparedStatement.setString(1, p.toString());
    11. preparedStatement.executeUpdate();
    12.  
    13. PreparedStatement statement = db.getConnection().prepareStatement("INSERT INTO 'points' (UUID, points) VALUES (?, ?)");
    14. statement.setString(1, p.toString());
    15. statement.setInt(2, currentPoints+points);
    16. statement.executeUpdate();
    17.  
    18. } catch (Exception e) {
    19. System.out.println("Error while interacting with SQL database!");
    20. if(Main.debug)
    21. e.printStackTrace();
    22. } finally {
    23. closeConnection();
    24. }
    25. }


    It is all working fine (the data is being correctly inserted in to the database), but the previous data isn't being removed. Is there something wrong with my DELETE statement.

    No error is being returned.

    Thanks for anyhelp you can offer.
     
  2. Offline

    fireblast709

    will181 '' is used for Strings, `` is used for columns, tables and databases. Moreover, you might want to look into INSERT...ON DUPLICATE KEY UPDATE... (in the case your UUID column is unique, but I dare to bet on that).
     
Thread Status:
Not open for further replies.

Share This Page