jdbc - Accessing MS Access Database using Java -


            try{                 class.forname("sun.jdbc.odbc.jdbcodbcdriver");                 string database =            "jdbc:odbc:driver={ms access database (*.accdb)};dbq=obn.accdb;";         c= drivermanager.getconnection(database, "", "");         s=c.createstatement();                     string = "in try";                     s.close();  // close statement                     c.close(); // close database. no more required                     joptionpane.showmessagedialog( null, string );              }             catch(exception e)             {                 string = "in exception";                 joptionpane.showmessagedialog( null, string );             } 

i have tried accessing ms access database using java using above code have exception. have tried few things

            c= drivermanager.getconnection("jdbc:odbc:driver={microsoft access driver (*.mdb)};dbq=obn.mdb");             s=c.createstatement(); 

in first 1 , second exception -

[microsoft][odbc driver manager] data source name not found , no default driver specified.  

...

                class.forname("sun.jdbc.odbc.jdbcodbcdriver");         c= drivermanager.getconnection("jdbc:odbc:obn");         s=c.createstatement(); 

tried doing this, adding obn in odbc datasources(32-bit) in windows , selecting path database. didnt work either.

it gave error

the specified dsn contains architecture mismatch between driver , application 

i dont use ms access have university project

verify using correct odbc driver name environment. need specify either...

{microsoft access driver (*.mdb)} 

...or...

{microsoft access driver (*.mdb, *.accdb)} 

...depending on whether want use older "jet" driver (only .mdb files, available 32-bit applications only) or newer "ace" driver (.mdb or .accdb files, can used 32- or 64-bit applications, may need installed separately if machine not have access on it).


Comments