我有一个巨大的MS Access数据库文件(aprrox.1gb)和大约5种不同的GUI(FXML)。每个fxml包含来自不同表的数据。我正在使用ucanaccess连接数据库。现在我在连接数据库时遇到问题。我永远不会得到联系。它适用于较小的数据库文件。我正在使用服务和任务为后台线程。有人能告诉我什么是解决这个问题的最佳方法。
private Service backgroundService;
private Connection ucaConn;
@FXML private void handleButtonAction(ActionEvent event){
backgroundService = new Service() {
@Override
protected Task createTask() {
return new Task() {
@Override
protected Object call() throws Exception {
try {
ucaConn = getUcanaccessConnection(DataCarrier.getInstance().getDatabaseLocation());
} catch (SQLException | IOException ex) {
Logger.getLogger(HomeController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
};
}
};
backgroundService.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent event) {
System.out.println("Done");
errorMessage.textProperty().unbind();
String timeStamp = new SimpleDateFormat("mm:ss").format(Calendar.getInstance().getTime());
System.out.println("End time: " + timeStamp);
}
});
errorMessage.textProperty().bind(backgroundService.messageProperty());
backgroundService.restart();
}
}
}
private static Connection getUcanaccessConnection(String pathNewDB) throws SQLException,
IOException {
String url = UcanaccessDriver.URL_PREFIX + pathNewDB + ";newDatabaseVersion=V2003";
return DriverManager.getConnection(url, "sa", "");
}