Jump to content

[1.17.1] No suitable driver found for jdbc:mysql


steakmans

Recommended Posts

Hello,

I'm trying to connect my mod to a mysql database and I get an SQLException.

Here are the dependencies and repos of my build.gradle

repositories {
    // Put repositories for dependencies here
    // ForgeGradle automatically adds the Forge maven and Maven Central for you

    // If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
    // flatDir {
    //     dir 'libs'
    // }
}

dependencies {
    minecraft 'net.minecraftforge:forge:1.17.1-37.0.58'
    implementation 'mysql:mysql-connector-java:8.0.26'
}

 

Link to comment
Share on other sites

Here it is:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/spell?autoReconnect=true&useSSL=false
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
	at TRANSFORMER/spellmod@0.0NONE/fr.steakmans.spellmod.mysql.Mysql.connect(Mysql.java:14)
	at TRANSFORMER/spellmod@0.0NONE/fr.steakmans.spellmod.Main.serverStarting(Main.java:51)
	at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247)
	at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239)
	at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
	at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
	at TRANSFORMER/forge@37.0.58/net.minecraftforge.fmllegacy.server.ServerLifecycleHooks.handleServerStarting(ServerLifecycleHooks.java:101)
	at TRANSFORMER/minecraft@1.17.1/net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:211)
	at TRANSFORMER/minecraft@1.17.1/net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:659)
	at TRANSFORMER/minecraft@1.17.1/net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:258)

 

Link to comment
Share on other sites

So here is the method were i'm trying to connect:

    public void serverStarting(FMLServerStartingEvent e) {
        mysql.connect("localhost", 3306, "db", "user", "mdp");
    }

And here is the class with all the functions

private Connection conn;

    public void connect(String host, int port, String database, String user, String password) {
        if(!isConnected()){
            try {
                conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public void disconnect(){
        if(isConnected()){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public boolean isConnected(){
        try {
            if((conn == null) || (conn.isClosed()) || conn.isValid(5)){
                return false;
            }
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }


    public Connection getConnection() {
        return conn;
    }

I'm dumb I forgot to shade the mysql driver

Edited by steakmans
Found the solution
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.