MYSQL Connector Driver Issue

Hi, I'm trying to implement an sql database, but I'm only getting the "No suitable driver found", anyone knows why it could be? implementation group: 'com.mysql', name: 'mysql-connector-j', version: '9.1.0' Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/name?user=user&password=password
37 Replies
JavaBot
JavaBot•6mo ago
āŒ› This post has been reserved for your question.
Hey @ponchisao326! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Yuvi
Yuvi•6mo ago
Hey @ponchisao326 Use Class.forName("com.mysql.cj.jdbc.Driver"); to load driver.
JavaBot
JavaBot•6mo ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
ponchisao326
ponchisao326OP•6mo ago
that's no longer necesary in modern sql connector versions, however I already tryed it with no result
JavaBot
JavaBot•6mo ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st•6mo ago
no result meaning same exception or different exception?
ponchisao326
ponchisao326OP•6mo ago
same exception 🫠 I mean, it just says "no suitable driver found for com. mysql.cj.jdbc.Driver"
dan1st
dan1st•6mo ago
wait, is it really that exact text? not something like no suitable driver found for jdbc:mysql:...? How are you running the project?
ponchisao326
ponchisao326OP•6mo ago
with the class.forName is what I said on Intellij with Gradle
dan1st
dan1st•6mo ago
Did it really not say ClassNotFoundException? Can you show the full stack trace?
ponchisao326
ponchisao326OP•6mo ago
let me check again Okay, let me code it again and I will show you
ponchisao326
ponchisao326OP•6mo ago
ponchisao326
ponchisao326OP•6mo ago
this is with the class.forName
ponchisao326
ponchisao326OP•6mo ago
This without the class.forName
dan1st
dan1st•6mo ago
oh this is a Minecraft thing make sure the JDBC driver is available at runtime like when the mod or whatever it is is loaded, make sure the JDBC driver is loaded with it
ponchisao326
ponchisao326OP•6mo ago
how can I make that?
dan1st
dan1st•6mo ago
idk how Minecraft does it
ponchisao326
ponchisao326OP•6mo ago
haha
dan1st
dan1st•6mo ago
maybe you need to add the JAR to the directory maybe it has a specific Gradle thing you have to mark the dependency with (i.e. maybe implementation may be the wrong option)
ponchisao326
ponchisao326OP•6mo ago
I tryed with runtimeOnly & compileOnly aswell as with implementation
dan1st
dan1st•6mo ago
like maybe there's a directory where you should put libs in maybe you have a config file where you also have to specify necesssary dependencies
ponchisao326
ponchisao326OP•6mo ago
I think that's not possible in minecraft modding 🫠
dan1st
dan1st•6mo ago
idk how Minecraft modding works
ponchisao326
ponchisao326OP•6mo ago
I know your point and its a good option, but I don't think there's a way to do that on minecraft modding
dan1st
dan1st•6mo ago
though actually there is something you could maybe do
ponchisao326
ponchisao326OP•6mo ago
My last option is to use an sqlite file and send it to the server via sftp or smth but I don't even know if it would be a good option though
dan1st
dan1st•6mo ago
Can you run Class.forName("com.mysql.cj.jdbc.Driver", true, getClass().getClassLoader());?
ponchisao326
ponchisao326OP•6mo ago
yeah, on my way Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
dan1st
dan1st•6mo ago
Did you still have the old Class.forName in it?
ponchisao326
ponchisao326OP•6mo ago
nope, I've replaced it
JavaBot
JavaBot•6mo ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
ponchisao326
ponchisao326OP•6mo ago
Okay, I've tryed in another project with maven and it's working, I don't know why I have the same thing on the two projects but it's not working 🫠
dan1st
dan1st•6mo ago
I think it's probably because of how Minecraft loads stuff
ponchisao326
ponchisao326OP•6mo ago
yeah, I think so or maybe a gradle problem but I don't know Okay, definitely is a minecraft forge problem
dan1st
dan1st•6mo ago
You could try printing JdbcConnection.class and check what happens with that
ponchisao326
ponchisao326OP•6mo ago
gonna try
JavaBot
JavaBot•6mo ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?