When I simply hit the run button on IntelliJ my code works perfectly but I’m trying to learn and get more comfortable in the terminal but cannot seem to figure out what I need to do to fix this.
if i simply use the command with the following code I get the following error
java Main
java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/bank_users_schema
try {
this.con = DriverManager.getConnection(url, user, pass);
}catch(Exception e) {
e.printStackTrace();
}
I’ve looked and seen people say it needs to add
Class.forName("com.mysql.jdbc.Driver");
If I do that then run my code I get the following error with my code like this
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
try {
Class.forName("com.mysql.jdbc.Driver");
this.con = DriverManager.getConnection(url, user, pass);
}catch(Exception e) {
e.printStackTrace();
}
I’ve also tried to run the commands
java -cp ../lib/mysql-connector-j-8.4.0.jar Main
Which results in the error
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
Tomas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.