Can't connect to phpMyAdmin

Discussion in 'Spigot Plugin Development' started by Sletonn, Apr 22, 2019.

  1. So I was testing a part of a big project code but when I'm trying to establish a connection between my plugin and phpMyAdmin nothing's happenning. Like litterally nothing no erros just this :

    Check at the time :
    Screenshot_1.png
    Code (Text):
    public class ConnectionBuilder {
     
        private String host, user, password, databaseName;
        private int port;
     
        public ConnectionBuilder(String host, String user, String password, String databaseName, int port) {
            this.host = host;
            this.user = user;
            this.password = password;
            this.databaseName = databaseName;
            this.port = port;
        }
     
        public String getURL() {
            return new StringBuilder()
                    .append("jdbc:mysql://")
                    .append(host)
                    .append(':')
                    .append(port)
                    .append('/')
                    .append(databaseName).toString();
        }

        public String getHost() {
            return host;
        }

        public String getUser() {
            return user;
        }

        public String getPassword() {
            return password;
        }

        public String getDatabaseName() {
            return databaseName;
        }

        public int getPort() {
            return port;
        }

    Code (Text):
        TEST(new ConnectionBuilder("localhost", "Jules", "password", "test", 81));
     
        private DatabaseConnecter databaseConnector;

        private Database(ConnectionBuilder connectionBuilder) {
            this.databaseConnector = new DatabaseConnecter(connectionBuilder);
        }

        public void initConnectionPool() {
              try {
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection(connectionBuilder.getURL(), connectionBuilder.getHost(), connectionBuilder.getPassword());
            } catch (SQLException | ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    I don't understand at all why is nothing happenning

    EDIT:
    I finally got an error :
    errror sql.png
     
  2. I'm confused, phpMyAdmin is an online database tool, you don't connect to it. You need to connect to MySQL on port 3306 but you are connecting on 81? I'm not sure what port that is.
     
  3. Problem fixed, I was uing the wrong port
     
  4. It was the port I had setup for Apache haha
     
  5. That's what I thought :p glad you got it sorted!
     
    • Like Like x 1
  6. I have another error though, I don't understand why my syntax is correct normally :
    [22:56:13 WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'most_uuid = 2941535451391147758 AND least_uuid = -7138619786107225087' at line 1
    [22:56:13 WARN]: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [22:56:13 WARN]: at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    [22:56:13 WARN]: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    [22:56:13 WARN]: at java.lang.reflect.Constructor.newInstance(Unknown Source)
    [22:56:13 WARN]: at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    [22:56:13 WARN]: at com.mysql.jdbc.Util.getInstance(Util.java:382)
    [22:56:13 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    [22:56:13 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
    [22:56:13 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
    [22:56:13 WARN]: at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
    [22:56:13 WARN]: at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
    [22:56:13 WARN]: at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
    [22:56:13 WARN]: at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
    [22:56:13 WARN]: at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2273)
    [22:56:13 WARN]: at com.sql.test.Main.initPlayer(Main.java:38)
    [22:56:13 WARN]: at com.sql.test.Main.onBreak(Main.java:99)
    [22:56:13 WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [22:56:13 WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [22:56:13 WARN]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [22:56:13 WARN]: at java.lang.reflect.Method.invoke(Unknown Source)
    [22:56:13 WARN]: at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298)
    [22:56:13 WARN]: at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    [22:56:13 WARN]: at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509)
    [22:56:13 WARN]: at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:264)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.PlayerInteractManager.dig(PlayerInteractManager.java:118)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:555)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(PacketPlayInBlockDig.java:41)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(PacketPlayInBlockDig.java:65)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:794)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:642)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:548)
    [22:56:13 WARN]: at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628)

    Here's my request :
    Code (Text):
            try {
                Connection connection = Database.ONIMA.getDatabaseConnector().getConnection();
                PreparedStatement statement = connection.prepareStatement("SELECT * FROM players "
                        + "INNER JOIN cooldowns ON players.most_uuid = cooldowns.most_uuid AND players.least_uuid = cooldowns.least_uuid"
                        + "WHERE most_uuid = ? AND least_uuid = ?");
               
                statement.setLong(1, uuid.getMostSignificantBits());
                statement.setLong(2, uuid.getLeastSignificantBits());
                statement.executeQuery();

                ResultSet resultSet = statement.getResultSet();

    And here are my tables :
    http://prntscr.com/nfh6dn
    http://prntscr.com/nfh6k5

    Do you knnow why ? Thanks
     
    • Funny Funny x 1
  7. Between "least_uuid" and "WHERE" you have forgotten a space
     
    • Like Like x 1
    • Agree Agree x 1

Share This Page