简体   繁体   中英

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;
        }
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM