0

I am trying to create a link to my Microsoft Access Database, but I get the error:

Exception : java.lang.ClassNotFoundException

Here is my code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBConnection
{
    public static void main(String[] args) 
    {
        try
               {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Load Driver
            Connection con = DriverManager.getConnection("jdbc:odbc:test"); //Create Connection with Data Source Name : HOD_DATA
            Statement s = con.createStatement(); // Create Statement
            String query = "select * from db"; // Create Query
            s.execute(query); // Execute Query 
            ResultSet rs = s.getResultSet(); //return the data from Statement into ResultSet
            while(rs.next()) // Retrieve data from ResultSet
            {
                System.out.print("\nUserName : "+rs.getString(1)); //1st column of Table from database
                System.out.print(" , Password : "+rs.getString(2)); //2nd column of Table 

            }
            s.close();
            con.close();
        }
        catch (Exception e) 
                {
            System.out.println("Exception : "+e);
        }
    }
}

I would greatly appreciate it if someone could tell me what I am doing wrong.

2
  • What does System.getProperty("java.version") return? Commented May 15, 2017 at 11:39
  • stackoverflow.com/questions/14229072/… -> this might clarify things :-) Commented May 15, 2017 at 11:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.