• Es freut uns dass du in unser Minecraft Forum gefunden hast. Hier kannst du mit über 130.000 Minecraft Fans über Minecraft diskutieren, Fragen stellen und anderen helfen. In diesem Minecraft Forum kannst du auch nach Teammitgliedern, Administratoren, Moderatoren , Supporter oder Sponsoren suchen. Gerne kannst du im Offtopic Bereich unseres Minecraft Forums auch über nicht Minecraft spezifische Themen reden. Wir hoffen dir gefällt es in unserem Minecraft Forum!

Spigot MySQL Timeout after 3 tries @,@

OnyxException

Minecrafter
Registriert
26 September 2018
Beiträge
22
Diamanten
300
Minecraft
Onyxzium
Hey zusammen!
Ich habe ein dicken Fehler wenn ich versuche mein Plugin zu starten


Code:
[14:17:08] [Server thread/INFO]: [XevelLobby] Enabling XevelLobby v1.0.0
[14:17:13] [Server thread/WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
[14:17:13] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[14:17:13] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[14:17:13] [Server thread/WARN]:     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[14:17:13] [Server thread/WARN]:     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.Util.getInstance(Util.java:408)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2094)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2019)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
[14:17:13] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[14:17:13] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[14:17:13] [Server thread/WARN]:     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[14:17:13] [Server thread/WARN]:     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
[14:17:13] [Server thread/WARN]:     at java.sql.DriverManager.getConnection(DriverManager.java:664)
[14:17:13] [Server thread/WARN]:     at java.sql.DriverManager.getConnection(DriverManager.java:247)
[14:17:13] [Server thread/WARN]:     at dev.xevelia.lobby.main.XEVE.MySQL.ASyncMySQL$MySQL.openConnection(ASyncMySQL.java:158)
[14:17:13] [Server thread/WARN]:     at dev.xevelia.lobby.main.XEVE.MySQL.ASyncMySQL$MySQL.<init>(ASyncMySQL.java:97)
[14:17:13] [Server thread/WARN]:     at dev.xevelia.lobby.main.XEVE.MySQL.ASyncMySQL.<init>(ASyncMySQL.java:24)
[14:17:13] [Server thread/WARN]:     at dev.xevelia.lobby.main.Lobby.onEnable(Lobby.java:40)
[14:17:13] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
[14:17:13] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
[14:17:13] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403)
[14:17:13] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381)
[14:17:13] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330)
[14:17:13] [Server thread/WARN]:     at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422)
[14:17:13] [Server thread/WARN]:     at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383)
[14:17:13] [Server thread/WARN]:     at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338)
[14:17:13] [Server thread/WARN]:     at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272)
[14:17:13] [Server thread/WARN]:     at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545)
[14:17:13] [Server thread/WARN]:     at java.lang.Thread.run(Thread.java:748)
[14:17:13] [Server thread/WARN]: Caused by: com.mysql.jdbc.exceptions.jdbc4.Communication***ception: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[14:17:13] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[14:17:13] [Server thread/WARN]:     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[14:17:13] [Server thread/WARN]:     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[14:17:13] [Server thread/WARN]:     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.SQLError.createCommunication***ception(SQLError.java:990)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2186)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2035)
[14:17:13] [Server thread/WARN]:     ... 27 more
[14:17:13] [Server thread/WARN]: Caused by: java.net.ConnectException: Connection refused (Connection refused)
[14:17:13] [Server thread/WARN]:     at java.net.PlainSocketImpl.socketConnect(Native Method)
[14:17:13] [Server thread/WARN]:     at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
[14:17:13] [Server thread/WARN]:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
[14:17:13] [Server thread/WARN]:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
[14:17:13] [Server thread/WARN]:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
[14:17:13] [Server thread/WARN]:     at java.net.Socket.connect(Socket.java:589)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
[14:17:13] [Server thread/WARN]:     at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
[14:17:13] [Server thread/WARN]:     ... 29 more

Die Klasse dahinter:
Code:
package dev.xevelia.lobby.main.XEVE.MySQL;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

import java.sql.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

public class ASyncMySQL {

    private static ExecutorService executor;
    private static MySQL sql;
    private static Plugin plugin;
    private static ASyncMySQL instance;



    public ASyncMySQL(Plugin pl, String host, int port, String user, String pw, String db) {
        try {
            plugin = pl;
            sql = new MySQL(host, port, user, pw, db);
            executor = Executors.newCachedThreadPool();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static ASyncMySQL getInstance() {
        return instance;
    }
    public ASyncMySQL(Plugin pl) {
        plugin = pl;
        instance = this;
    }


    public static void update(String statement) {
        executor.execute(() -> sql.queryUpdate(statement));
    }

    public static void update(PreparedStatement statement) {
        executor.execute(() -> sql.queryUpdate(statement));
        try {
            statement.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void query(PreparedStatement statement, Consumer<ResultSet> consumer) {
        executor.execute(() -> {
            ResultSet result = sql.query(statement);
            Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result));
        });
    }

    public static void query(String statement, Consumer<ResultSet> consumer) {
        executor.execute(() -> {
            ResultSet result = sql.query(statement);
            Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result));
        });
    }

    public static PreparedStatement prepare(String query) {
        try {
            return sql.getConnection().prepareStatement(query);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public MySQL getMySQL() {
        return sql;
    }

    public static class MySQL {
        private String host, user, password, database;
        private int port;

        private Connection conn;

        public MySQL() {

        }

        public MySQL(String host, int port, String user, String password, String database) throws Exception {
            this.host = host;
            this.port = port;
            this.user = user;
            this.password = password;
            this.database = database;

            this.openConnection();
        }

        public void queryUpdate(String query) {
            checkConnection();
            try (PreparedStatement statement = conn.prepareStatement(query)) {
                queryUpdate(statement);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public void queryUpdate(PreparedStatement statement) {
            checkConnection();
            try {
                statement.executeUpdate();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

        public ResultSet query(String query) {
            checkConnection();
            try {
                return query(conn.prepareStatement(query));
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public ResultSet query(PreparedStatement statement) {
            checkConnection();
            try {
                return statement.executeQuery();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public Connection getConnection() {
            return this.conn;
        }

        private void checkConnection() {
            try {
                if (this.conn == null || !this.conn.isValid(10) || this.conn.isClosed())
                    openConnection();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public void openConnection() throws Exception {
            this.conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useJDBCCompliantTimezoneShift=true&&serverTimezone=UTC&&useUnicode=true&autoReconnect=true", user, password);
        }

        public void closeConnection() {
            try {
                this.conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                this.conn = null;
            }
        }
    }
}



Hostname und alles wird in der Main Klasse gesetzt
 

Chrisliebär❤️

nur echt mit ❤️
Moderator
Registriert
19 Mai 2014
Beiträge
1.675
Diamanten
830
Der Zielserver lehnt die Verbindung ab, das ist ein Fehler auf dem TCP Layer und die Datenbank wird nicht Mal erreicht. Nachdem ich mir Grad auch deinen Code angesehen hab, solltest du dir dein Vorhaben vielleicht nochmals überlegen. Fast in jeder Zeile machst du was kaputt.

Ich verstehe auch nicht warum so viele Leute sich Abstraktionen um die SQL API bauen. Es hat einen Grund warum das alles so funktioniert, wie es funktioniert.
 
Zuletzt bearbeitet:
Oben