JavaFX:tableview不会从数据库填充(ucanaccess)

时间:2015-08-04 14:03:59

标签: javafx tableview javafx-8 ucanaccess

我的应用程序包含一个tabpane,每个选项卡都是一个包含控制器的嵌套fxml。 每个fxml文件都有一个tableview,用于从microsoft访问数据库中检索数据。 一些只有字符串列的表可以工作并填充,但另一个(Demandes)有一个整数列和一个localdate列不会填充。我不知道导致问题的是什么。

这里是" Demandes"的嵌套控制器标签:

public class DemandesController{

@FXML
private TableView<Demande> demandesTable;
@FXML
private TableColumn<Demande, Integer> numColumn;
@FXML
private TableColumn<Demande, String> societeColumn;
@FXML
private TableColumn<Demande, LocalDate> dateDemandeColumn;
@FXML
private TableColumn<Demande, LocalDate> dateSignatureColumn;
@FXML
private TableColumn<Demande, String> villeColumn;

private ObservableList<Demande> demandes = FXCollections.observableArrayList();

private MainApp mainApp;
String BD_URL = mainApp.getBdUrl();

public DemandesController(){

}
public ObservableList<Demande> getBulletins(){
    return demandes;
} 

@FXML
private void initialize() {

    getDemandesData();
    numColumn.setCellValueFactory(cellData -> cellData.getValue().numDemandeProperty().asObject());
    societeColumn.setCellValueFactory(cellData -> cellData.getValue().societeProperty());
    dateDemandeColumn.setCellValueFactory(cellData -> cellData.getValue().dateDemandeProperty());
    dateSignatureColumn.setCellValueFactory(cellData -> cellData.getValue().dateSignatureProperty());
    villeColumn.setCellValueFactory(cellData -> cellData.getValue().villeProperty());

}    
public void setMainApp(MainApp mainApp){         
    this.mainApp = mainApp;        
    demandesTable.setItems(getBulletins());        
}

public void getDemandesData(){
    Task task = new Task<Void>() {
        @Override
        protected Void call() throws Exception {     

       try (Connection con = DriverManager.getConnection(BD_URL)) {
           Statement stmt = con.createStatement();
           ResultSet res = stmt.executeQuery("SELECT * FROM [Demandes-tab]");
           while (res.next()) {
               int numDemande = res.getInt(1);
               String societe = res.getString(2);
               LocalDate dateDemande = res.getDate(3)
                       .toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
               LocalDate dateSignature = res.getDate(4)
                       .toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
               String ville = res.getString(5);

               demandes.add(new Demande(numDemande,societe,dateDemande,
                       dateSignature,ville));                   
           }
       }return null;

        }            
    };
new Thread(task).start();           
}  } 

和初始化嵌套fxmls和控制器的父控制器:

public class TabsController{

private MainApp mainApp;

@FXML private AnchorPane Bulletins;
@FXML private BulletinsController BulletinsController;

@FXML private AnchorPane Demandes;
@FXML private DemandesController DemandesController;

@FXML private AnchorPane Personneltest;
@FXML private PersonnelController PersonneltestController;

@FXML private AnchorPane Personnel;
@FXML private PersonnelController PersonnelController;

@FXML private AnchorPane Produit;
@FXML private ProduitController ProduitController;

@FXML private AnchorPane Societes;
@FXML private SocietesController SocietesController;

@FXML
private void initialize() {        
}          
public void setMainApp(MainApp mainApp) {
   this.mainApp = mainApp; 

   BulletinsController.setMainApp(mainApp);
   PersonneltestController.setMainApp(mainApp);

   DemandesController.setMainApp(mainApp);
}    }

这也是在正确的地方添加的:

<Tab text="Demandes">
           <content>
              <fx:include fx:id="Demandes" source="Demandes.fxml" />
           </content>
        </Tab>

如果有人能告诉我为什么tableview不会填充这将是一个很大的帮助。谢谢。 ps:哦,我也删除了数据库网址,看看它是否重要,没有任何改变。这是否意味着它根本没有连接到数据库?

0 个答案:

没有答案