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

Dani AI

Generated

As noted, the old JDBC‑ODBC bridge is not available in Java 8 and later — that is why the JVM cannot load the sun.jdbc.odbc driver. Use a pure‑Java JDBC driver for Access instead of trying to resurrect the removed bridge. (docs.oracle.com)

The simplest, well‑tested option is UCanAccess: it is a pure‑Java JDBC driver that uses Jackcess and HSQLDB under the hood and ships with the small set of JARs you need. Rather than mixing a MySQL connector (which does nothing for Access) download the UCanAccess binary distribution and use the jars it includes (ucanaccess + jackcess + hsqldb + commons‑lang + commons‑logging). That distribution also documents the ucanload/UCANACCESS_HOME approach for avoiding classpath conflicts. (sourceforge.net)

If your downloads unpacked to a src folder, you probably grabbed source distributions instead of the binary jars. Fixes:

  • Download the UCanAccess “-bin.zip” (not the -src.zip) and copy the JARs from its lib folder into your project. (sourceforge.net)
  • For individual libraries you can get binary ZIPs or direct JARs from the projects (Apache Commons Lang / Commons Logging) or Maven Central (for direct .jar downloads). For example, binary downloads for Commons Lang and Commons Logging are available from Apache and the built jars are on Maven Central. (commons.apache.org)
  • HSQLDB documentation and distributions explain where to find hsqldb.jar if you need it separately. (hsqldb.org)

Quick Eclipse workflow (apply these after you have the correct -bin JAR files):

  1. Extract the UCanAccess -bin.zip and pick the jars from the root and the lib folder.
  2. In Eclipse: Project → Properties → Java Build Path → Libraries → Add External JARs → select all required jars → Apply.
  3. Use a UCanAccess URL, for example:
String url = "jdbc:ucanaccess://C:/full/path/to/database.accdb";
Connection conn = DriverManager.getConnection(url);

Common gotchas: make sure the Access file is closed in Access when your app opens it; ensure the jars are on the runtime classpath (Run Configurations); and if you ever go back to ODBC, match JVM bitness with the ODBC driver/ODBC Admin (32 vs 64‑bit). If classpath conflicts appear, follow the UCanAccess loader/UCANACCESS_HOME instructions in the binary distro. (sourceforge.net)

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.