0

I can't connect to ms access with java8 using netbeans IDE it keeps showing me exception when i run the program "java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver" I tried using ucanaccess drivers as well as jdbc- odbc bridge.

import java.sql.*;


public class Connectivity {
    static String db;
    public Connectivity()
    {
        try{
            String path = new java.io.File("pvtDB.mdb").getAbsolutePath();
            db ="JDBC:ODBC:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ="+path;
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection(db);
            Statement st = con.createStatement();
            ResultSet rs=st.executeQuery("Select * from Attendence_T");
            while(rs.next())
            {
                 System.out.println("Hello Welcome to connection");
            }
            /*Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            String msAccDB = "D:/Netbeans/Attendance/pvtDB.mdb";
            String dbURL = "jdbc:ucanaccess://" + msAccDB;
            Connection conn = DriverManager.getConnection(dbURL); 
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM Attendence");
            while(rs.next())
            {
                System.out.println("Connection Established");
            }*/
        }catch(NullPointerException |ClassNotFoundException |SQLException ex){
            System.out.println(ex);
        }   
    }
   /* public void doConnection(){
        try{
            /*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection(db);
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from Attendence_T");
            while(rs.next()){
                System.out.println(rs.getObject(1));
            }
        }catch(SQLException | ClassNotFoundException ex){
            System.out.println(ex.toString());

        }
    }*/
    public static void main(String...argS){
        new Connectivity();
    }
}
  • If you did try UCanAccess and got a different error, you should create a new question and show the code using that and the error you got. The error you did show in this question is covered by the answer to the duplicate question. – Andreas Mar 12 '18 at 05:40
  • After trying all answers given in duplicate question i have posted this question my problem didn't get resolved using yous answers.So tell me another solution otherwise get lost – Kashish Gupta Mar 12 '18 at 07:16
  • How can we tell you another solution, when you don't even show how your code using UCanAccess doesn't work? In what way doesn't it work, and how is that different from the solutions already provided? But, I'll follow your advice and let lost, so now you won't even get my help. I'd say good luck to you, but with that attitude, you're going to need a lot more than luck to get any help on here. – Andreas Mar 12 '18 at 15:30

0 Answers0