Solved Increase by 1 a mysql value

Discussion in 'Spigot Plugin Development' started by JeckBiagio_, Jul 31, 2018.

Thread Status:
Not open for further replies.
  1. Hi, this is the method that i've tried but i get an error (i want to increase of 1 a value in mysql)

    Code (Java):
    public static void addKill(Player player)
        {
            if(existPlayer(player))
            {
                try {
                    getConnection().prepareStatement("UPDATE stats SET player_kills='player_kills'+1 WHERE player_uuid='"+ player.getUniqueId().toString() +"';").executeUpdate();
                }catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    and this is the error
    Code (Text):
    Data truncation: Truncated incorrect DOUBLE value: 'player_deaths'
     
  2. Can you post the code where you create the table?
     
  3. The actual java code where you create the table columns.
     
  4. i create the table columns by myself; directly in phpmyadmin
     
  5. Does the column have a default value? If the column's value is NULL, then you need to check for null.
    Code (SQL):
    ISNULL(player_kills, 0) + 1
    Also agree with slees. The error kind of sounds like a data type issue, and we don't know the constraints of the column unless you show us the creation code.
     
  6. What was the exact query you executed to create the table?
     
  7. I've resolved the problem just putting 2 brackets
    Code (Java):
    public static void addDeath(Player player)
        {
            if(existPlayer(player))
            {
                try {
                    getConnection().prepareStatement("UPDATE stats SET player_deaths=(player_deaths)+1 WHERE player_uuid='"+ player.getUniqueId().toString() +"';").executeUpdate();
                }catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
     
    • Like Like x 1
Thread Status:
Not open for further replies.