我正在开发一个连接到Access数据库的Java应用程序,我可以在本地运行时连接到eclipse上的Access数据库。
但是当我导出项目的jar并在我的本地机器上运行可执行jar时(在我将它部署到prod之前我发现这个错误)。我之前没看到它是如何工作的,之后也没有工作。
public boolean openConnection() {
boolean rtn = false;
try {
String myDB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=" + this.pathToDatabase + ";UID=" + this.username +
";PWD="+ this.password + ";";
logger.debug("Connecting to database using: " + myDB);
this.dbConn = DriverManager.getConnection(myDB, "", "");
rtn = true;
} catch (SQLException ex) {
printSQLException(ex);
}
return rtn;
}
例外:
2013-12-04 18:26:55,270 [main] WARN GenericDatabaseWrapper - SQLState: IM002
2013-12-04 18:26:55,338 [main] WARN GenericDatabaseWrapper - Error Code: 0
2013-12-04 18:26:55,366 [main] WARN GenericDatabaseWrapper - Message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified