java.lang.ClassNotFoundException:net.ucanaccess.jd

2019-09-13 13:55发布

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);
        }
    }
}

2条回答
一夜七次
2楼-- · 2019-09-13 14:21

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.

查看更多
SAY GOODBYE
3楼-- · 2019-09-13 14:25

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

查看更多
登录 后发表回答