Solved Error with MySQL

Renay

New member
Dec 16, 2024
2
0
1
21
Germany
Hello everyone,

I've recently started working with the Velocity API and encountered an issue when trying to connect my plugin to a MySQL database. I've added the mysql-connector-j Maven dependency, but I keep running into an SQLException with the message "No suitable JDBC driver found."

The strange part is that connecting to MySQL works perfectly fine in other programs and plugins, but for some reason, this error only occurs when using the Velocity API.

Does anyone have an idea what might be causing this? Any help would be greatly appreciated!

Thanks in advance!

Error message: https://pastebin.com/5VEHaJPH
pom.xml (repository and dependencies): https://pastebin.com/2d756Sf1
using JDK 22
 
Version Output
Velocity 3.4.0-SNAPSHOT (git-4aa9ee77-b455)
Copyright 2018-2024 Velocity Contributors. Velocity is licensed under the terms of the GNU General Public License v3.
PaperMC - GitHub

Warrior

New member
Oct 11, 2023
1
0
1
The Netherlands
The common causes for this issue that I've seen are forgetting to register your driver with the DriverManager, or not having the shade plugin present.

To register your shaded driver:
Java:
try {
    DriverManager.registerDriver((Driver) Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance());
catch (ReflectiveOperationException | SQLException e) {
    // handle exception
}

If you're already registering the driver and have confirmed that the driver is included in your jar via the shade plugin and it's still not working, please send your full mysql class and pom file to help further debug the issue.
 

Renay

New member
Dec 16, 2024
2
0
1
21
Germany
The common causes for this issue that I've seen are forgetting to register your driver with the DriverManager, or not having the shade plugin present.

To register your shaded driver:
Java:
try {
    DriverManager.registerDriver((Driver) Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance());
catch (ReflectiveOperationException | SQLException e) {
    // handle exception
}

If you're already registering the driver and have confirmed that the driver is included in your jar via the shade plugin and it's still not working, please send your full mysql class and pom file to help further debug the issue.
Thanks for your reply! I realized my mistake - I didn’t extract the MySQL connector into the output JAR, I just placed it there. Took me way too long to figure that out, haha! Anyway, have a nice day :D