try {
            /*  Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
                String loc = "jdbc:odbc:Library";
                               String filename = "C:\\Users\\Krishal Lad\\Desktop\\Library.mdb";
                                String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=";
                               database+= filename.trim() + ";DriverID=22;}"; // add on to the end 
                con = DriverManager.getConnection (database);*/
                            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String database = 
                  "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ=Library.mdb;";
                        System.out.println("connecting to database...");
                Connection conn = DriverManager.getConnection(database);

            }
            catch (ClassNotFoundException cnf)  {
                JOptionPane.showMessageDialog (null, "Driver not Loaded...");         
                System.exit (0);
            }
            catch (SQLException sqlex) {
                JOptionPane.showMessageDialog (null, "Unable to Connect to Database...");
                            sqlex.printStackTrace();
                System.exit (0);
            }

This is not able to connect to the Library database. I have created a ODBC data source Library.

This is the error message:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:233)
    at library.Logon.<init>(Logon.java:113)
    at library.Splash.<init>(Splash.java:37)
    at library.Splash.main(Splash.java:49)

b26ba768ebd2f8ad8b4b8d2613807bf6

Dani AI

Generated

Most likely root cause: a JVM/ODBC bitness mismatch. 's fix (switching the runtime to a 32‑bit JDK and pointing the app at the .mdb) is exactly the usual solution — the legacy JDBC‑ODBC bridge and the Microsoft Access ODBC/ACE drivers must match the JVM bitness. On 64‑bit Windows there are two ODBC managers and two sets of drivers, so a DSN created with the wrong one will be invisible to the running JVM. Also note the JDBC–ODBC bridge was removed from Oracle JDK starting with Java 8, so relying on it is brittle for modern runtimes.

Checklist and practical steps that address the error you saw:

  • Confirm the JVM bitness: run java -version and look for "64‑Bit" or "32‑Bit" in the output.
  • Use the matching ODBC admin when creating DSNs: C:\Windows\SysWOW64\odbcad32.exe for 32‑bit DSNs on 64‑bit Windows, C:\Windows\System32\odbcad32.exe for 64‑bit.
  • Install the Microsoft Access Database Engine (ACE) driver that matches the JVM (32‑ or 64‑bit).
  • Prefer a System DSN (not a per‑user DSN) when the app runs under a service or different account.
  • With DSN‑less connections, use absolute paths and confirm file permissions; avoid pointing at a desktop path if the process runs as another user.

Longer‑term, use a pure‑Java Access solution instead of the JDBC‑ODBC bridge. UCanAccess is a commonly used option (it bundles Jackcess and runs on modern JDKs). Example connection pattern:

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C:/full/path/Library.mdb");

Include the ucanaccess (and its Jackcess/HSQDB) jars on the classpath. Note: 's jTDS suggestion targets SQL Server/Sybase, not Access — jTDS won't help unless the data is migrated to SQL Server.

Changed default jdk to 32 bit jdk and set the path to the database.
Solved.

Hi;
try this : jtds
or this

best regards;

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.