java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Exception occurring. Why?

后端 未结 5 1829
暗喜
暗喜 2020-11-22 09:13

I have created an MS Access database and assigned a DSN to it. I want to access it through my Java application.

This is what I am doing:

public class         


        
5条回答
  •  情歌与酒
    2020-11-22 09:50

    Setup:

    My OS windows 8 64bit
    Eclipse version Standard/SDK Kepler Service Release 2
    My JDK is jdk-8u5-windows-i586
    My JRE is jre-8u5-windows-i586
    

    This how I overcome my error.

    At the very first my Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") also didn't work. Then I login to this website and downloaded the UCanAccess 2.0.8 zip (as Mr.Gord Thompson said) file and unzip it.

    Then you will also able to find these *.jar files in that unzip folder:

    ucanaccess-2.0.8.jar
    commons-lang-2.6.jar
    commons-logging-1.1.1.jar
    hsqldb.jar
    jackcess-2.0.4.jar
    

    Then what I did was I copied all these 5 files and paste them in these 2 locations:

    C:\Program Files (x86)\eclipse\lib
    C:\Program Files (x86)\eclipse\lib\ext
    

    (I did that funny thing becoz I was unable to import these libraries to my project)

    Then I reopen the eclipse with my project.then I see all that *.jar files in my project's JRE System Library folder.

    Finally my code works.

    public static void main(String[] args) 
    {
    
        try
        {
    
            Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Hasith\\Documents\\JavaDatabase1.mdb");
            Statement stment = conn.createStatement();
            String qry = "SELECT * FROM Table1";
    
            ResultSet rs = stment.executeQuery(qry);
            while(rs.next())
            {
                String id    = rs.getString("ID") ;
                String fname = rs.getString("Nama");
    
                System.out.println(id + fname);
            }
        }
        catch(Exception err)
        {
            System.out.println(err);
        }
    
    
        //System.out.println("Hasith Sithila");
    
    }
    

提交回复
热议问题