简体   繁体   中英

java.lang.ClassNotFoundException: org.firebirdsql.jdbc.FBDriver

I am not able to access the Firebird configuration string, and it works perfectly in MySQL.

package testej;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class TesteConexao {

    public static void main(String[] args) {
        try {
            
            Class.forName("org.firebirdsql.jdbc.FBDriver");
            String URL = "jdbc:firebirdsql:localhost/3050:C:/DB/DASHBOARD.FDB";
            String usuario = "SYSDBA";
            String senha = "masterkey";
            Connection conn = DriverManager.getConnection(URL, usuario, senha);
            System.out.println("Conexão efetuada com sucesso!");
            conn.close();
        } catch (ClassNotFoundException | SQLException ex) {
            
            ex.printStackTrace();
            
        }

    }

}

java version "1.8.0_311", my firebird is 3.0.10 33601 x64, jdbc driver jaybird4.0.8 1.8,jaybird 3.0.12 1.8, jaxb.2.3.0

java.lang.ClassNotFoundException: org.firebirdsql.jdbc.FBDriver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at testej.TesteConexao.main(TesteConexao.java:12)

The error means that Jaybird is not on the classpath. When running your application, make sure you specify the correct classpath (you need both jaybird-4.0.8.java8.jar and connector-api-1.5.jar ):

For example:

java -cp .;D:\libs\jaybird-4.0.8.java8\jaybird-4.0.8.java8.jar;D:\libs\jaybird-4.0.8.java8\lib\connector-api-1.5.jar testej.TesteConexao

or (only) jaybird-full-4.0.8.java8.jar :

java -cp .;D:\libs\jaybird-4.0.8.java8\jaybird-full-4.0.8.java8.jar testej.TesteConexao

When running from Linux, use : as the classpath separator instead of ; .

As an aside, explicitly loading the driver with Class.forName hasn't been necessary since Jaybird 2.2 on Java 6 or higher.

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