-2

Here IS Code Any Suggestions When i am trying to access the data base it shows error after making jar file

   File f = new File("E:\\DB\\**\\***.mdb");
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                    JOptionPane.showMessageDialog(null, "Driver loded succesfully");
                    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+f.getAbsolutePath();
                    connection = DriverManager.getConnection( database ,"",""); 

                    JOptionPane.showMessageDialog(null, "connection is"+connection);

                }catch(Exception e){
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null,"erroris"+ e);;
                }
Ahmad
  • 770
  • 9
  • 21
  • Don't you thing it might be a good idea to include the error here? There is a LOT that can go wrong in that code snippet. Do you have the ODBC driver in your classpath? Is that the real filename you're using? – f1sh Aug 01 '16 at 21:31
  • Have your application display the result returned by `System.getProperty("java.version")`. What does it say? – Gord Thompson Aug 01 '16 at 22:38
  • Yes i am using real File name – Ahmad Aug 01 '16 at 23:36
  • System.getProperty("") same error – Ahmad Aug 01 '16 at 23:36
  • 2
    The point of displaying `System.getProperty("java.version")` is not to fix the problem with your application, it is to show the version of Java you are running when the application fails. (Hint: If your application is running under Java 8 then the JDBC-ODBC Bridge is not available and your code simply will not work.) – Gord Thompson Aug 01 '16 at 23:48
  • No i am using old version which had facility of JDBC-ODBC – Ahmad Aug 01 '16 at 23:52
  • 1
    Are you sure that your JAR file is running under the same version of Java as when your application is running in Eclipse? Eclipse could be running the code under Java 7 (if that is the JRE specified in the Eclipse settings), while the JAR file could be running under Java 8 (if that is the default JRE registered with the operating system). – Gord Thompson Aug 02 '16 at 12:49
  • Yes its JAVA(version) Compatibility issue issue Thanks for Help :) Gord Thompson – Ahmad Jan 29 '17 at 11:54

2 Answers2

0

ClassNotFoundException means that your program can't find the odbc driver class, try including the jar file in your path.

Gherbi Hicham
  • 2,416
  • 4
  • 26
  • 41
0

Its Only java Compatibility Issue . ODBC connection is not available in new versions of Java . So it work on old version on which i made. Thanks to
@Gord Thompson

Ahmad
  • 770
  • 9
  • 21