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);*/
                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...");
                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(
    at sun.jdbc.odbc.JdbcOdbc.standardError(
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(
    at java.sql.DriverManager.getConnection(
    at java.sql.DriverManager.getConnection(
    at library.Logon.<init>(
    at library.Splash.<init>(
    at library.Splash.main(


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

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.