Solved MySQL Credits not working!?!?

Discussion in 'Plugin Development' started by WingedMLGPro, Apr 19, 2015.

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

    WingedMLGPro

  2. Offline

    mythbusterma

    @WingedMLGPro

    Well first of all, you're going to lag your server hard with all those SQL queries on the main thread. You should really do something about that.
     
  3. Offline

    ItsMattHogan

    1# Use prepared statements
    2# Put all of your SQL queries in their own thread

    As for why it's not working -- you should have a stacktrace in console, which will tell you what's wrong, please post it here.
     
  4. Offline

    WingedMLGPro

  5. Offline

    API_Tutorials

    @WingedMLGPro
    The table you are trying to use doesn't exist.
     
  6. Offline

    WingedMLGPro

  7. Offline

    ItsMattHogan

    It says on the 31st line that the table "SwiftyCreditsTest" doesn't exist: "20.04 04:04:35 [Server] WARN com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mc19421.SwiftyCredits' doesn't exist"

    Please learn how to read a stacktrace...

    Not necessarily. Make sure the table exists and you're spelling it correctly.
     
  8. Offline

    WingedMLGPro

    @ItsMattHogan But, im trying to create the table in my MySQL class.

    @ItsMattHogan Ok, i got the table wrong, but now there is a problem with the actual credits api.
    Everytime i do set credits it creates a new colum and when i get credits it always returns null.
    Here is my CreditsAPI class:
    http://pastebin.com/H9vLXpJk

    If you can see while it would be doing that plz tell me.
    Thanks
    WingedMLGPro

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  9. Offline

    Protophite

    @WingedMLGPro

    Code:
    MySQL.update("INSERT INTO `SwiftyCreditsTest`(`UUID`, `PlayerName`, `Credits`) VALUES ('" + p.getUniqueId() + "','" + p.getName() + "','" + credits + "')");
    
    Code:
    ResultSet rs = MySQL.getResult("SELECT Credits FROM SwiftyCreditsTest WHERE UUID='" + p.getDisplayName() + "'");
    
    Player#getUniqueId()
    Player#getDisplayName() don't return the same thing that is why your getCredits method is null.
     
  10. Offline

    WingedMLGPro

    Last edited by a moderator: Jun 12, 2016
  11. Offline

    Protophite

    It's because your column is not a UUID type. UUID#toString

    @WingedMLGPro

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  12. Offline

    WingedMLGPro

  13. Offline

    Protophite

    @WingedMLGPro
    Code:
    if (rs.next()){
        rs.getInt("Credits");
    }
    return null;
    wait this is the problem.. You are always returning null

    use
    Code:
    return rs.getInt("Credits");
     
    Last edited: Apr 20, 2015
  14. Offline

    WingedMLGPro

    NVM, i solved it myself, the error was i forgot to put return infront of rs.getint("Credits");
    Thanks for help!
     
Thread Status:
Not open for further replies.

Share This Page