0

我有两个类 Customer 和 Product.i 将此类值存储在数据库中作为两个表,一个用于客户,另一个用于产品。我使用内部连接来检索这些数据。我想在 JavaFX TreeTable 中显示这些数据。有很多教程,但它们只适用于一个类。到目前为止,这是我的代码,但它不起作用。我不是 javaFX pro。

Connection con;
PreparedStatement ps;
ResultSet rs;

@FXML
private JFXButton close;

@FXML
private JFXTreeTableView<Product> detailsTable;


@FXML
private JFXComboBox<String> searchStatus;

@FXML
private JFXComboBox<String> searchLocation;

@FXML
private TreeTableColumn<Customer, String> cname;

@FXML
private TreeTableColumn<Customer, String> cnic;

@FXML
private TreeTableColumn<Customer, String> cphone;

@FXML
private TreeTableColumn<Product, String> pbrand;

@FXML
private TreeTableColumn<Product, String> ptype;

@FXML
private TreeTableColumn<Product, Integer> prcc;

@FXML
private TreeTableColumn<Product, String> plocation;

@FXML
private TreeTableColumn<Product, String> pshoptype;

@FXML
private TreeTableColumn<String, Date> pdate;


@FXML
void OnClickSearch(KeyEvent event) {

}

@FXML
void searchByLocation(ActionEvent event) {

}

@FXML
void searchByStatus(ActionEvent event) {

}

private ObservableList<Customer> cData;

private ObservableList<Product> pData;




@Override
public void initialize(URL url, ResourceBundle rb) {

@Override
public void initialize(URL url, ResourceBundle rb) {

    con= DBConnect.connect();
    cData=FXCollections.observableArrayList();
    pData= FXCollections.observableArrayList();
    try {
        rs=con.createStatement().executeQuery("SELECT c.customerName,c.customerNic,c.customerPhone,p.productBrand,p.productType,p.productRcc,p.productLocation,p.productShopType,p.productDate From customer as c INNER JOIN product as p ON c.customerId=p.customerId ");
    } catch (SQLException e) {
        System.out.println("GET DATA TO TABLE ERROR");
        e.printStackTrace();
    }

    try {
        while(rs.next()){

            //pData.add(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getInt(6),rs.getString(7),rs.getString(8),rs.getDate(9));
            cData.add(new Customer(rs.getString(1),rs.getString(2),rs.getString(3)));
            pData.add(new Product (rs.getString(4),rs.getString(5),rs.getInt(6),rs.getString(7),rs.getString(8),rs.getDate(9)));

        }
    } catch (SQLException e) {
        System.out.println("RS.Next() Error");
        e.printStackTrace();
    }

    cname.setCellValueFactory(new PropertyValueFactory<Customer,String>("customerNam"));
    cnic.setCellValueFactory(new PropertyValueFactory<Customer,String>("nic"));
    cphone.setCellValueFactory(new PropertyValueFactory<Customer,String>("phone"));
    pbrand.setCellValueFactory(new PropertyValueFactory<Product,String>("brand"));
    ptype.setCellValueFactory(new PropertyValueFactory<Product,String>("type"));
    prcc.setCellValueFactory(new PropertyValueFactory<Product,Integer>("rccNo"));
    plocation.setCellValueFactory(new PropertyValueFactory<Product,String>("location"));
    pshoptype.setCellValueFactory(new PropertyValueFactory<Product,String>("shopType"));
    pdate.setCellValueFactory(new PropertyValueFactory<Customer,Date>("date"));


    System.out.println("For Testing");
}
4

0 回答 0