0

I am trying to make a basic JDBC program using MS Access. I downloaded the Ucanacess.zip file and I got in total 6 .jar files namely: ucanaccess-3.0.7, ucanload, commons-lang-2.6, commons-logging-1.1.1, hsqldb, and jackcess-2.1.3

I added them to the classpath as Environment Variables(Computer->Properties->Advanced System Settings->Environment Variable).

But when I run my Code it gives an Exception java.lang.ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver

Here is the code

class DB {
    public static void main(String[] args) {
        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        }
        catch(ClassNotFoundException ex) {
            System.out.println(ex);
        }
    }
}

1 Answers1

1

You have to run :

  • javac DB.java
  • java -cp . -cp ucanaccess-3.0.7.jar -cp ucanload.jar ... DB

The former to compile DB.java. The latter to run java by setting classpath, "." is the directory where resides the compiled "DB.class"

Pascal Heraud
  • 365
  • 2
  • 8
  • Instead of specifying `-cp` multiple times, you can also do it once and separate the jars by `;` (Windows) or `:` (Linux and Mac) – Mark Rotteveel Dec 31 '16 at 12:54
  • Now it's telling me that it was not able to find or load main class DB. Here is the command: **java -cp . -cp ucanaccess-3.0.7.jar;ucanload.jar;commons-lang-2.6.jar;commons-logging-1.1.1.jar; hsqldb.jar; jackcess-2.1.3 DB** – Prakhar Singh Jan 01 '17 at 09:38
  • what is package declaration of DB class ? if no package you must be in the foldaer containing DB.class. – Pascal Heraud Jan 01 '17 at 11:28
  • They are already in the same folder. – Prakhar Singh Jan 02 '17 at 08:41