Posted September 12, 20214 yr 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' }
September 12, 20214 yr 1 hour ago, steakmans said: I get an SQLException Please post full logs, including full errors messages. An exception can be caused by approximately 1 zillion things.
September 12, 20214 yr Author 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/[email protected]/fr.steakmans.spellmod.mysql.Mysql.connect(Mysql.java:14) at TRANSFORMER/[email protected]/fr.steakmans.spellmod.Main.serverStarting(Main.java:51) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) at TRANSFORMER/[email protected]/net.minecraftforge.fmllegacy.server.ServerLifecycleHooks.handleServerStarting(ServerLifecycleHooks.java:101) at TRANSFORMER/[email protected]/net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:211) at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:659) at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:258)
September 12, 20214 yr I would check out https://stackoverflow.com/questions/8146793/no-suitable-driver-found-for-jdbcmysql-localhost3306-mysql for some suggestions. You should also post a link to a github repo of the project, or at the very least post classes trying to connect to the database.
September 12, 20214 yr Author 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 October 3, 20213 yr by steakmans Found the solution
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.