MySQL Doesn't work on 1.17.1

Discussion in 'Plugin Development' started by TerThesz, Sep 29, 2021.

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

    TerThesz

    I made a plugin that uses MySQL for 1.16.4 and everything works just fine but as soon as I switched to 1.17.1 I got an error (btw I am using a docker server just for testing. I tried running the plugin outside docker still didn't work).

    Log of console: https://pastebin.com/raw/2xYf7T7f

    Code:
    Code:
        public void mysqlInit() {
            host = getConfig().getString("host");
            username = getConfig().getString("username");
            password = getConfig().getString("password");
            database = getConfig().getString("database");
            table = getConfig().getString("table");
            port = getConfig().getInt("port");
           
            try {
                synchronized (this) {
                    if (getConnection() != null && !getConnection().isClosed()) return;
                   
                    Class.forName("com.mysql.jdbc.Driver");
                    setConnection(DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/"
                    + database, username, password));
                   
                    Bukkit.getConsoleSender().sendMessage("MySQL Connected.");
                }
            } catch (SQLException e) {
                exceptionMessage(e.getMessage());
               
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                exceptionMessage(e.getMessage());
               
                e.printStackTrace();
            }
        }
       
        public void createTableIfNotExists() {
            try {
                String sqlCreate = "CREATE TABLE IF NOT EXISTS `" + table + "` ("
                + "  `UUID` CHAR(36) NOT NULL,"
                + "  `password` VARCHAR(64) NOT NULL,"
                + "  `password_salt` CHAR(5) NOT NULL,"
                + "  `ip_address` VARCHAR(64) NOT NULL,"
                + "  `ip_salt` CHAR(5) NOT NULL,"
                + "  `premium` INT(1) NOT NULL,"
                + "  PRIMARY KEY (`UUID`)"
                + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;";
               
                Statement stmt = (Statement) getConnection().createStatement();
                stmt.execute(sqlCreate);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
     
  2. Offline

    Kars

    Looks like you can't load Statement (class) from the classpath. It could be because the dependency is not loaded correctly.
    Are you using Maven?
     
  3. Offline

    davidclue

    @TerThesz Perhaps this may help you
    I don't know why you are collecting IP addresses of servers, doesn't seem like something a plugin should be doing but regardless why not use a boolean instead of an int for your premium field? The punctuation marks may be screwing with your statements I had issues with using them and when I removed them it fixed my problem.
     
  4. Offline

    Strahan

    MySQL doesn't give a darn what version of MC you use. Like Kars said, check your dependencies and ensure you have everything setup right.

    Boolean is just an alias for tinyint(1), so using a numeric is not really different. Though using int(1) will still consume 4 bytes vs tinyint/bool's 1 byte.

    Also if by punctuation you refer to the backticks (`), it's actually good to get in the habit of using them. If at some point one makes a table with a field that you aren't aware is reserved, your code will puke if it isn't in backticks like that. Though honestly, I prefer to just be careful with fields and avoid it too because I'm lazy, lol.
     
  5. Offline

    TerThesz

    @Kars @Strahan

    I use the IP addresses for sessions and They are salt-hashed. And I actually removed the premium part because I don't need it anymore.

    @Kars
    I don't actually know I was using this tutorial:

    @Kars
    I just searched up what maven is and I tried using it. I added this dependency:

    Code:
      <dependencies>
          <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <version>5.1.47</version>
          </dependency>
      </dependencies>
    but it still gives me the same error

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 29, 2021
  6. Online

    timtower Administrator Administrator Moderator

    @TerThesz What is your plugin doing in the end?
     
  7. Offline

    TerThesz

    @timtower it's an authentication plugin.
     
  8. Online

    timtower Administrator Administrator Moderator

    @TerThesz Authentication to what? And why would it need a connection to your server?
     
  9. Offline

    TerThesz

    @timtower Authentication of players when they join (login and register)
     
  10. Online

    timtower Administrator Administrator Moderator

    @TerThesz Sounds like something that you don't need if you have online-mode set to true.
    Locking because of that reason.
    And the questionable connection to your server.
     
    Tim_M and davidclue like this.
Thread Status:
Not open for further replies.

Share This Page