Pay attention to Microsoft Access Driver (*. in MDB), the driver is followed by a space. I found this problem only half a day after debugging today ~~~~~~~~~~
Import java. SQL .*;
Public class dbconnection
{
Public static void main (string ARGs [])
{
Try {
// String strurl = "JDBC: ODBC: Driver = {Microsoft Access Driver (*. mdb)}; DBQ = dB. mdb ";
String strurl = "JDBC: ODBC: Driver = {Microsoft Access Driver (*. mdb)}; DBQ = dB. mdb ";
// String strurl = "JDBC: ODBC: Driver = {Microsoft Access Driver (*. mdb)}; DBQ = dB. mdb"; // This is the NO-DSN Method
// String strurl = "JDBC: ODBC: Test ";
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
System. Out. println ("before connection ");
Connection conn = drivermanager. getconnection (strurl );
Statement stmt = conn. createstatement ();
Resultset rs1_stmt.exe cutequery ("select * from test ");
If (Rs. Next ())
{
System. Out. println (Rs. getstring ("ID "));
}
} Catch (exception E)
{
System. Out. println (E );
}
}
}