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());
              }
        }
    }

Recommended Answers

All 2 Replies

The JDBC-ODBC Bridge has been removed from Java 8, so you won't be able to directly use it any longer.

Maybe this SO Thread on the matter can help you continue your work.

I did downlload and added the following JAR files in my projects:
UCanAccess (ucanaccess-2.x.x.jar)
Jackcess (jackcess-2.x.x.jar)

But for some reason when I download the below 3 files. It download as a src folder:
HSQLDB (hsqldb.jar, version 2.2.5 or newer)
commons-lang (commons-lang-2.4.jar, or newer)
commons-logging (commons-logging-1.0.4.jar, or newer)

Do you how may I change it jar files?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.