简体   繁体   中英

Jar File Error (java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver)

Sir in Netbeans when I run program it runs successfully but when I make jar file and run it then there is this error :

java.lana.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

Please answer me that how to solve that exception.

Here is my code:

public class DatabaseManager {

static Connection con;

static{

    System.out.println("Connecting To Database ... ... ...");
    try{

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

        con = DriverManager.getConnection("jdbc:odbc:Pepsi");

    } catch (ClassNotFoundException | SQLException ex) {

        JOptionPane.showMessageDialog(null, ex);

        System.exit(0);
        Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}

I have also used ucanaccess me libariers for direct access to database.

con = DriverManager.getConnection("jdbc:ucanaccess:C:\\Users\\Administrator\\Documents\\NetBeansProjects\\Pepsi\\Pepsi.accdb");

When I ran java while the exception comes but in Netbeans it works properly.

It is running in netbeans IDE because you have all java reference libraries added in your project. Please verify your classpath when running jar directly. I guess your are not having rt.jar in your classpath. Check this if your are using Java 8 java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Exception occurring. Why?

I guess the some classes are not properly added to your jar file as external dependencies. Please verify that all the external jar files that you are using in your project are successfully added to your jar file.

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