I am trying to connect access database with eclipse but it is not working.
I first created data source in "ODBC Data Source Administrator(32-bits)" for windows
than I add the jar file
But I am getting an error:
ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
SQLException: No suitable driver found for jdbc:odbc:J2EE_Database
public class ex01 {
public static void main(String[] args) {
String url = "jdbc:odbc:J2EE_Database";
Connection con;
Statement stmt;
String query = "Select * from user";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
// Returns a ResultSet that contains the data produced by the query; never null
ResultSet rs = stmt.executeQuery(query);
System.out.println("Course Data:");
System.out.println("Course\tTitle\tCredits");
while (rs.next())
{
String course = rs.getString("COURSE");
String description = rs.getString("DESCRIPTION");
int credits = rs.getInt("CREDITS");
System.out.println(course + "\t" + description + "\t" + credits);
}
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
}
}