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 the statement
c.close(); // Close the database. Its no more required
JOptionPane.showMessageDialog( null, string );
}
catch(Exception e)
{
string = "IN exception";
JOptionPane.showMessageDialog( null, string );
}
I have tried accessing a MS Access Database using Java using the above code always have an Exception. I have tried a few things
c= DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=obn.mdb");
s=c.createStatement();
In the first one and the second i get exception -
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
...
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c= DriverManager.getConnection("jdbc:odbc:obn");
s=c.createStatement();
Tried doing this like this, adding OBN in ODBC Datasources(32-bit) in windows , selecting the path to the database. But it didnt work either.
It gave the error
The specified DSN contains an architecture mismatch between the Driver and Application
I Normally dont use MS Access but i have to for a University Project