0
我想初始化一個TableView元素,並且爲此我需要從數據庫中獲取數據。方法(位於控制器類中)從數據庫獲取數據並返回ObservableList,引發SQLException和ClassNotFoundException。當我把這個方法在初始化(),我得到一個錯誤:在JavaFX控制器類中拋出異常初始化()的方法
overridden method does not throw 'java.sql.SQLException'
的只有大約方法,使其工作是做一個按鈕,並將其鏈接到該方法。但是,這並不會自動填充TableView。 有沒有辦法在該階段打開時調用該方法,而沒有整個「按鈕」方法?
代碼:
public void initialize(URL location, ResourceBundle resources) {
// Link table cells to Rates object
currencyCol.setCellValueFactory(cellData -> cellData.getValue().currencyCodeProperty());
buyCol.setCellValueFactory(cellData -> cellData.getValue().buyRateProperty().asObject());
sellCol.setCellValueFactory(cellData -> cellData.getValue().sellRateProperty().asObject());
}
@FXML
public void populateRates() throws SQLException, ClassNotFoundException {
ObservableList<Rates> rates = RatesDAO.showRates();
currencyTable.setItems(rates);
System.out.println(rates);
}
非常感謝你,這的確的確工作:) –