skip to Main Content

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.

image of the jar file in classpath

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


  1. 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

    Login or Signup to reply.
  2. First make sure your connection string is correct. Then the database name avoids the use of dashes (-).

    The same code works fine for me.

    enter image description here

    Download the connection package here.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search