0

I have seen this error popping up many times. I have searched the web and tried stuff like adding the mysql-connector file to the buildpath, but nothing worked out for me.

This Code works when running with spigot, this is only another Linux user and not spigot.

Im running this Code in a plugin for the JTSServermod for TS3 on a Linux Debian with Java 8.

The full error message is:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3307/db
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at net.mysticsouls.TeamSpeakBot.utils.NameUUIDUtils.connect(NameUUIDUtils.java:31)
    at net.mysticsouls.TeamSpeakBot.utils.Updater.start(Updater.java:11)
    at net.mysticsouls.TeamSpeakBot.TeamSpeakBot.activate(TeamSpeakBot.java:45)
    at de.stefan1200.jts3servermod.JTS3ServerMod.e(Unknown Source)
    at de.stefan1200.jts3servermod.JTS3ServerMod.b(Unknown Source)
    at de.stefan1200.jts3servermod.i.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)

And my Code calling it is:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;

public class NameUUIDUtils {

    private static final String host = "localhost";
    private static final String port = "3307";
    private static final String database = "db";
    private static final String username = "username";
    private static final String password = "*********";
    private static Connection connection;

    public static Connection getConnection() {
        return connection;
    }

    public static boolean isConnected() {
        return connection != null;
    }

    public static void connect() {
        if (!isConnected()) {
            try {
                connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username,
                        password);
                System.out.println("[NameUUID] MySQL connected!");
            } catch (SQLException ex) {
                ex.printStackTrace();
                System.out.println("[NameUUID] MySQL failed to connect!");
            }
        }

        if (isConnected()) {
            try {
                PreparedStatement preparedStatement = getConnection().prepareStatement(
                        "CREATE TABLE IF NOT EXISTS CoinSystem (Spielername VARCHAR(100), UUID VARCHAR(100), Coins INT(100), Strafpunkte INT(100))");
                preparedStatement.executeUpdate();
                preparedStatement.close();
                System.out.println("[NameUUID] MySQL Table created!");
            } catch (SQLException ex) {
                System.out.println("[NameUUID] MySQL Table failed to create!");
            }
        }
    }
}

What am i doing wrong.

Gerolmed
  • 3
  • 8

0 Answers0