ucanaccess jdbc connection without IDE

705 views Asked by At

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

There are 1 answers

4
Pascal Heraud On

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"