1
package myJavaPrograms;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class AccessDBFiles {
    public static void main(String[] args) throws SQLException  {
        Connection conn=DriverManager.getConnection(
                "jdbc:ucanaccess://C:\\TESTFILE\\Database11.accdb");
        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery("SELECT * FROM myTable");
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    }

I am getting exception in thread main as Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder External Jars added to project

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Seems like it cant find given class. Actually it should be in commons lang. So, I'd suggest rebuild project or change version of commons lang and logging libs – Vasif Oct 26 '18 at 15:40

2 Answers2

0

I see you are using UCanAccess, the pure JDBC driver. This case you have to load this driver:

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

Alternatively, you can load the JDBC/ODBC driver class like this:

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

This case, the URL format is like this:

jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;

Also, don't forget to close the resources: ResultSet, Statement and Connection.

0

UCanAccess uses Jackcess, and Jackcess uses commons-lang (v2.x), not commons-lang3. All of the required dependencies for UCanAccess are included in the lib folder of the UCanAccess distribution (.bin.zip file).

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418