1

I'm beginner with java and using console to compile and run my programs. I'm trying to read data from MS Access .accdb file with ucanaccess driver. As i have added 5 ucanaccess files to C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext, but still getting Exception java.lang.ClassNotFoundException:net.ucanaccess.jdbc.ucanaccessDriver. Here is my code.

import java.sql.*;
public class jdbcTest 
{
    public static void main(String[] args)
    {
        try
        {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            String url = "jdbc:ucanaccess://C:javawork/PersonInfoDB/PersonInfo.accdb";
            Connection conctn = DriverManager.getConnection(url);
            Statement statmnt = conctn.createStatement();
            String sql = "SELECT * FROM person";
            ResultSet rsltSet = statmnt.executeQuery(sql);
            while(rsltSet.next())
            {
                String name = rsltSet.getString("name-");
                String address = rsltSet.getString("address");
                String phoneNum = rsltSet.getString("phoneNumber");

                System.out.println(name + " " + address + " " + phoneNum);
            }
            conctn.close();
        }
        catch(Exception sqlExcptn)
        {
            System.out.println(sqlExcptn);
        }
    }
}
sumer
  • 21
  • 1
  • 1
  • 4
  • 1
    It's wrong, you shouldn't added 5 ucanaccess jar files to C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext but to the classpath. For more configuration informations see here: http://stackoverflow.com/questions/21955256/manipulating-an-access-database-from-java-without-odbc – jamadei Dec 11 '15 at 08:00
  • 1
    Possible duplicate of [UCanAccess Initializer Error (compile/run without IDE)](http://stackoverflow.com/questions/34214108/ucanaccess-initializer-error-compile-run-without-ide) – Gord Thompson Dec 11 '15 at 13:22

2 Answers2

1

Please add JDBC driver jar to lib folder. Download URL download jar

MrEyebr0w5
  • 37
  • 7
Bharat DEVre
  • 539
  • 3
  • 13
  • Dear @dullpointer, please point to the 3.0.3 new distribution(not the old one 3.0.2) – jamadei Dec 11 '15 at 08:05
  • 1
    ucanaccess 3.0.3 distribution file does not contain jdbc jar. Also i have seen http://stackoverflow.com/questions/21955256/manipulating-an-access-database-from-java-without-odbc, it describes the solution only with IDEs but not with console. – sumer Dec 11 '15 at 09:57
  • The console.bat in the ucanaccess distribution may give you an advice on how to set the classpath. You absolutely don't need any different jar from five ones mentioned in the Gord's post , all needed jars are in the distribution (jdbc is java standard, not a separated jar)! – jamadei Dec 11 '15 at 10:43
-1

I tried the method mentioned by Gord in his post Manipulating an Access database from Java without ODBC and used eclipse instead of command line compile and run. Also to learn eclipse basics, i watched video tutorial https://www.youtube.com/watch?v=mMu-JlBrYXo. Finally i was able to read my MS Access data base file from my java code.

Community
  • 1
  • 1
sumer
  • 21
  • 1
  • 1
  • 4