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

后端 未结 5 1831
暗喜
暗喜 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 10:08

    in JDK 8, jdbc odbc bridge is no longer used and thus removed fro the JDK. to use Microsoft Access database in JAVA, you need 5 extra JAR libraries.

    1- hsqldb.jar

    2- jackcess 2.0.4.jar

    3- commons-lang-2.6.jar

    4- commons-logging-1.1.1.jar

    5- ucanaccess-2.0.8.jar

    add these libraries to your java project and start with following lines.

    Connection conn=DriverManager.getConnection("jdbc:ucanaccess://");
    Statement s = conn.createStatement();
    

    path could be like E:/Project/JAVA/DBApp

    and then your query to be executed. Like

    ResultSet rs = s.executeQuery("SELECT * FROM Course");
    while(rs.next())
        System.out.println(rs.getString("Title") + " " + rs.getString("Code") + " " + rs.getString("Credits"));
    

    certain imports to be used. try catch block must be used and some necessary things no to be forgotten.

    Remember, no need of bridging drivers like jdbc odbc or any stuff.

提交回复
热议问题