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

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

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.