I am using Eclipse, java8
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
and than I added the jar file (mysql-connector-java-5.1.35-bin)
But I am getting an error:
ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ex01.main(ex01.java:34)
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());
e.printStackTrace();
}
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("CoursetTitletCredits");
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());
}
}
}