Weird MySql bug

Discussion in 'Plugin Development' started by nuno1212sss, Jan 30, 2015.

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

    nuno1212sss

    When I try to save stuff to the mysql database when a player leaves, it works just fine, but when I try to save it when the player is in the server doing nothing it does not work, wtf?
    Here is the code
    Code:
    public synchronized void save(PlayerData d){
            try{
                if(isinDatabase(d.getUUID())){
                    PreparedStatement s = c.prepareStatement("UPDATE player SET TOKENS=?,EXP=?,COINS=? WHERE UUID=?");
                    s.setString(1,String.valueOf(d.getTokens()));
                    s.setString(2,String.valueOf(d.getExp()));
                    s.setString(3,String.valueOf(d.getCoins()));
                    s.setString(4,d.getUUID().toString());
                    s.executeUpdate();
                    s.close();
                    Bukkit.broadcastMessage("SAVED" + d.getCoins());
                    Bukkit.broadcastMessage("UUID: " + d.getUUID().toString());
                }
            }catch (SQLException e){
                e.printStackTrace();
                this.refresh();
                this.save(d);
            }
    
        }
    Saving when a player leaves:
    Code:
    public void handleLeave(UUID u){
            final PlayerData d = getPlayer(u);
            this.d.remove(d);
            if(getPlayer(u) == null){
            }
            MySql.getIns().save(d);
        }
    Saving on a random ocasion:
    Code:
    public void save(UUID u){
            PlayerData d = getPlayer(u);
            MySql.getIns().save(d);
        }
    Note that the PlayerData is not return null, the method is executing perfectly, but the database stays the same, wtf xD
     
  2. Offline

    guitargun

    @nuno1212sss is the player already in the database? you only have the code when the player is already in the database and not the new insert command
     
  3. Offline

    nuno1212sss

  4. Offline

    WinX64

    Hmm, are you ever calling the save method?
    Off-topic question: Why are your storing everything as strings, even integers :confused:?
     
  5. Offline

    nuno1212sss

    @WinX64 Yes, and because it is the easy way to read it from the linux terminal xD and I just like to store everything in strings
     
  6. Offline

    WesJD

    @nuno1212sss There's a setInt method in PreparedStatement, no need to use the valueOf method in String.
     
  7. Offline

    nuno1212sss

    @WesJD Not the problem :s
     
  8. Offline

    mythbusterma

    @nuno1212sss

    But it's still a problem.

    Also, how are you certain the player is in the database, that they aren't updating, etc.
     
Thread Status:
Not open for further replies.

Share This Page