I need to connect to my database but I keep getting an error that says "driver not found".
I have added mariadb-java-client-3.0.8.jar jar file and it is still not working.
And this works pretty well on NetBeans, but I need to know how to fix that in VScode IDE. Do you know what I am missing?
import java.sql.Connection;
import java.sql.DriverManager;
public class App {
public static void main(String[] args) throws Exception {
try {
Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost:3306/cpit305-project", "root", "");
System.out.println("working");
} catch (Exception e) {
System.err.println(e);
}
}
}
The exception:
java.sql.SQLException: No suitable driver found for jdbc:mariadb://localhost:3306/cpit305-project
2
Answers
I have faced the same problem. I solved it by exporting classpath into my .zshrc file.
Add this to you shell:
export CLASSPATH=/path/mysql-connector-java-ver.jar:$CLASSPATH
First make sure your connection string is correct. Then the database name avoids the use of dashes (
-
).The same code works fine for me.
Download the connection package here.