MySQL JDBC driver not found using mysql driver dependency

Thice

New member
Feb 8, 2024
2
0
1
Dear

I was working on a plugin, that connects to the MySQL database.
When connecting to MySQL the way I did in paper would not work and results in the error: No suitable driver found for <database_url>
I've fixed this by adding: Class.forName("com.mysql.cj.jdbc.Driver");
And adding the MySQL connector dependency. Now I still got the error.
I've also tried to add it via the jar, in the modules, also resulting in the same error.

Java version: 20

See images.

Thank you for the help! :D
 

Attachments

  • maven.png
    maven.png
    124.7 KB · Views: 9
  • error.png
    error.png
    98.5 KB · Views: 8
  • mysql.png
    mysql.png
    32.7 KB · Views: 8
  • pom.png
    pom.png
    28.7 KB · Views: 9

Digital'Inc

New member
Feb 10, 2024
2
0
1
The maven-shade-plugin didn't work for me. What helped me was adding (-cp "path\to\mariadb-java-client-3.3.0.jar") to the startup .bat file. But I would like to do without it. Could you show a minimal working plugin using mysql built through maven?
 

_1ms

New member
Jun 30, 2024
3
0
1
Thanks, I've found a solution.
I'm having the same issue now, I shade the com.mysql:mysql-connector-j:9.0.0 in the jar with gradle, but it still gives the same java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/mydb error as yours. Do you think you can say how you've solved it?
 

getsmod0

New member
Oct 5, 2024
1
0
1
Dear

I was working on a plugin, that connects to the MySQL database.
When connecting to MySQL the way I did in paper would not work and results in the error: No suitable driver found for <database_url>
I've fixed this by adding: Class.forName("com.mysql.cj.jdbc.Driver");
And adding the MySQL connector dependency. Now I still got the error.
I've also tried to add it via the jar, in the modules, also resulting in the same error.
bisp payment check
Java version: 20

Thank you for the help! :D
you're on the right track by adding the MySQL connector dependency and specifying the driver. Since you're still encountering the "No suitable driver found" error, here are a few things to double-check:

  1. Dependency Scope: Ensure the MySQL connector is added in the correct scope (e.g., as a compile or runtime dependency if you're using Maven or Gradle).
  2. Classpath: Confirm that the MySQL connector jar is included in your runtime classpath. This is especially important if you're manually adding jars or using a modular setup.
  3. JDBC URL Format: Double-check the format of your database URL (e.g., jdbc:mysql://localhost:3306/dbname). Make sure it's correctly formatted and includes the proper protocol.
  4. Driver Version Compatibility: Since you're using Java 20, ensure that your MySQL connector version is compatible with that Java version.
If you've addressed these and still face the issue, please share more details about your environment or build tool setup.