0

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.

Manesh Kumar
  • 1
  • 1
  • 1
  • I believe the JDBC/ODBC driver has been removed from Java 8. It was never much more than a toy. Don't use it. Use a vendor driver. – user207421 Sep 11 '15 at 23:09

2 Answers2

0

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?

Community
  • 1
  • 1
Vijay k
  • 5
  • 7
0

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.

Sachin Malhotra
  • 1,211
  • 2
  • 11
  • 24