Mox
Mox

Reputation: 2463

java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver

I have the mariadb-java-client-1.4.2.jar included in my eclipse. And the project compiles to jar perfectly fine on my windows machine. The compiled jar file is then being executed on a Fedora 22 machine with mariadb install. However the above error gets thrown when it tries to register the driver. Anyone knows how it can be solved ?

Here is the source code of the function.

    @Override
    protected final Connection initialValue() {
        try {
            Class.forName("org.mariadb.jdbc.Driver"); // touch the mariadb driver
        } catch (final ClassNotFoundException e) {
            System.err.println("ERROR" + e);
        }
        try {
            final Connection con = DriverManager.getConnection(
                ServerConstants.SQL_URL, 
                ServerConstants.SQL_USER, ServerConstants.SQL_PASSWORD);
            allConnections.add(con);
            return con;
        } catch (SQLException e) {
            System.err.println("ERROR" + e);
            return null;
        }
    }

Upvotes: 5

Views: 24809

Answers (1)

Mansour
Mansour

Reputation: 686

Like the error states, it can not find the class. This can be due to missing jar for Maria DB driver, or duplicate jars. If you are packaging your project as a Jar, then it is unlikely eclipse will include mariadb driver.

So the first step to troubleshoot your problem is to find if the driver's jar exists or added to your classpath, or if there's another jar with the same class exsits on the classpath.

Upvotes: 3

Related Questions