Solved MySQL error maybe?

Discussion in 'Plugin Development' started by GaaTavares, Sep 13, 2013.

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

    GaaTavares

    Hey, i'm having a issue with the mysql. The connection works perfectly, but i think i mistaked here, i want to send more messages if the player is a MOD, his "Cargo" is MOD. Can anyone tell me the error? The console doesn't show any erros, and when i type the command, only send me the first line, "Bem-vindos"....
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("help")){
    2. p.sendMessage(ChatColor.RED + "Bem-vindo! Comandos disponíveis: ");
    3. try {
    4. String cargo = "MOD";
    5. ResultSet res = MySQL.querySQL("SELECT * FROM USUARIOS WHERE Nome = '" + p.getName() + "';");
    6. res.next();
    7. if (res.getString("Cargo") == cargo){
    8. p.sendMessage(ChatColor.GOLD + "/lista - Lista todos os jogadores online");
    9. p.sendMessage(ChatColor.GOLD + "/sopa - Compre 5 sopas por $50");
    10. p.sendMessage(ChatColor.GOLD + "/reparar - Repare seus itens por $200");
    11. p.sendMessage(ChatColor.GOLD + "/entrar - Entra em um evento (se estiver disponível no momento)");
    12.  
    13. }
    14. }catch (SQLException e1) {
    15. e1.printStackTrace();
    16. }
    17.  
    18. }
     
  2. Offline

    CubieX

    Use .equals() to compare the string. Not =
     
  3. Offline

    GaaTavares

    No, this isnt the error ( you probably are crazy for say i'm stupid on this and go learn ) but i already tried ;/
     
  4. Offline

    CubieX

    Are you sure your .querySQL() method is working correctly?
    Maybe you do not have the needed data in your DB, so the resultSet will be empty.
    Where do you create this data in the DB?

    And in your case, you have to compare the strings with .equals().
    Using "=" will not work here, because those two Strings will never be the exact same object.
    Only their content may match.
    And if those Strings do not always have the exact same case, use .equalsIgnoreCase() instead.
     
  5. Offline

    dark navi

    1) I'd use prepared statements when setting up a query.
    2) You should do if(res.next()) THEN check it's contents.
    3) As others have said, I'd use string.equalsIgnoreCase("mod").
    4) You don't need a semi-colon at the end of the query.
    5) I'd check and see if this query is actually pulling the info that you want. Try using the MySQL Workbench to create your queries before hand so you can test them.
    6) You need to close your result set. If you declare it before the try {} you can add a finally {} clause to the try/catch and close it in there automatically when the try/catch is done.


    Edit: And don't be that guy who finds out what is wrong and then doesn't post. If you take the time to change the issue to 'Solved,' make a post and say what fixed it.
     
Thread Status:
Not open for further replies.

Share This Page