Solved MySQL - INSERT query

Discussion in 'Plugin Development' started by PDKnight, Dec 31, 2014.

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

    PDKnight

    Hi there, I have a little problem. My plugin adds rows to the table, when I executed an "/irc [message]" command. BUT, the plugin doesn't add rows to the start of the table:
    [​IMG]

    My code:

    Code:
    public synchronized static void addRowToTable(String player, String message){
            try{
                PreparedStatement sql = connection
                        .prepareStatement("INSERT INTO `ircchat_mc` VALUES (?,?);");
                sql.setString(1, player);
                sql.setString(2, message);
                sql.execute();
               
                sql.close();
               
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    Thanks for any solution.

    PS: I'm sorry, but my english is so bad xD I'm Slovak
    PS(2): I've opened the connection in "onEnable()" and closed in "onDisable()"
     
  2. Offline

    timtower Administrator Administrator Moderator

    @PDKnight Add an auto increment to your table.
     
  3. Offline

    PDKnight

    @timtower Great, and how to do it? What's the auto increment? Sorry, I'm new in MySQL :D
     
  4. Offline

    timtower Administrator Administrator Moderator

    @PDKnight Add a column in phpmyadmin, add toggle it on.
     
  5. Offline

    PDKnight

  6. Offline

    timtower Administrator Administrator Moderator

    @PDKnight That is indeed the one that I mean
     
  7. Offline

    PDKnight

    @timtower Okay, and why is it good for? I think it's just another column in my table, like others :)
    [​IMG]
     
  8. Offline

    timtower Administrator Administrator Moderator

    @PDKnight Auto increment will give each record its own unique value, a number from 1 ... <depends on the amount of records>
    Makes it easy to see how many records you had already, and you can sort on it.
     
  9. Offline

    PDKnight

  10. Offline

    elraro

    edit the TABLE STRUCTURE, and look in id for auto_increment, check the tick and accept.
     
  11. Offline

    PDKnight

Thread Status:
Not open for further replies.

Share This Page