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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
A. Bhatnagar
  • 45
  • 2
  • 9

0 Answers0