ClassNotFoundException: com.mysql.cj.jdbc.Driver
Posted by: Katelyn Eitel
Date: December 15, 2019 07:24PM

Hello everyone!

I am currently working on a Java Swing project in IntelliJ IDEA. I have created a folder called 'lib' inside the main directory of the project. Inside the lib folder has the MySQL connector (mysql-connector-java-8.0.18.jar). The connector is the independent platform download. The 'lib' folder has been added under File->Project Structure...->Libraries. Everything runs as it should in the IDE, but when I run the project outside the IDE, I get the following error:

D:\Library\Development\SUN Online\App\Release\SUN Calculator v132>java -jar "SUN Calculator.jar"
java.sql.SQLException: No suitable driver found for jdbc:mysql://IP:3306/Database_Name?noAccessToProcedureBodies=true

at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Database.MySQL.openConnection(MySQL.java:50)
at Database.MySQL.testConnection(MySQL.java:33)
at Utility.Updater.checkUpdates(Updater.java:48)
at Main.Calculator.main(Calculator.java:47)

Here is part of the code for the class 'MySQL' below:

public void openConnection()
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");

// Line below is line 50.
connection = DriverManager.getConnection("jdbc:mysql://IP:330/Database_Name?noAccessToProcedureBodies=true", "User", "Password");
}
catch (SQLException || ClassNotFoundException e)
{
e.printStackTrace();
}
}

The database is running on another machine through a host. I removed the IP, Database, User, and Password information from the connection strings above.

Options: ReplyQuote


Subject
Written By
Posted
ClassNotFoundException: com.mysql.cj.jdbc.Driver
December 15, 2019 07:24PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.