MySQL Problem

Discussion in 'Plugin Development' started by Hellborn5456, Dec 29, 2014.

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

    Hellborn5456

    Need some help. When i send information to my MySQL it will insert into the gamestate. but when the gamestate switchs ingame it adds a another row and say that gamestate. So theres now 2 rows. but i only wont 1 that will switch between states.
    Here code:
    Code:
       
    public static void sendGameState(GameStatus state) throws SQLException {
            Statement st = Connection.con.createStatement();
            if(checkGameState(state)){
                st.executeUpdate("UPDATE g1 SET gamestate='"+state+"'");
            }else{
                st.executeUpdate("INSERT INTO g1(gamestate) VALUES ('"+state+"')");
            }
        }
        }
     
  2. Offline

    97WaterPolo

    @Hellborn5456
    I don't use a lot of MySQL in my plugins, but I would say, try having both to update, or both to insert, one of them is just adding it instead of updating.

    Personally I think both need to be update, makes more sense. Update should add the value and if there is no row it should create it, where as INSERT would just create a new one instead of updating the old one.
     
  3. Offline

    ColonelHedgehog

    You'll need to delete the old data first.

    DELETE FROM `g1` WHERE... something like that.
     
Thread Status:
Not open for further replies.

Share This Page