Access
/**
* 連結資料庫,offiec 2007 以上
* @param f
* @param DBpath
* @return
*/
public Connection getACCDBConnection(Frame f, String DBpath) {
try {
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="
+ DBpath;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
return conn;
} catch (Exception e) {
new MessageBox().getMessageBox(f, "無法連接資料庫");
new MessageBox().error(f, e.toString());
}
return null;
}
/**
* 連結資料庫
*
* @param f
* @param DBpath
* @return
*/
public Connection getMDBConnection(Frame f, String DBpath) {
try {
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="
+ DBpath;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection(url);
return conn;
} catch (Exception e) {
new MessageBox().getMessageBox(f, "無法連接資料庫");
new MessageBox().error(f, e.toString());
}
return null;
}