I’m trying in Java to establish a connection to mysql. When I run my program I get a error that “No suitable driver found for jdbc:mysql://localhost:3306/bot”. I’ve searched on the internet and found a solution that I need to add Class.forName("com.mysql.cj.jdbc.Driver");
before writing connection = DriverManager.getConnection();
.
Said, done. When I run my program now i’ll get a new different error.
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at net.advancedbots.discordbot.mysql.SQLHandler.connectDatabase(SQLHandler.java:52)
at net.advancedbots.discordbot.DiscordBotPlugin.main(DiscordBotPlugin.java:24)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:413)
at java.base/java.lang.Class.forName(Class.java:404)
at net.advancedbots.discordbot.mysql.SQLHandler.connectDatabase(SQLHandler.java:50)
It’s pretty clear to me that the error is a ClassNotFoundException but I don’t know how to fix the error. I’ve tried already the following steps:
- adding the connector-java into my pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
- downloaded manually “Connector/J” went into my project structure -> modules -> dependencies and added the .jar-file into my module-dependencies
So after now a couple of hours I don’t know how to fix it. Can anyone help me with this please?