0

I have been at this for a while now and can't seem to solve it, I'm attempting to populate a tableview from my database, the tableview fills with the right amount of rows however all of the cells remain blank. The values are Integer, String, Double, Int, String the blank rows in the tableview

This is the class in which the tableview is loaded

public class FXMLDocumentTakeOrderController implements Initializable {

    @FXML private TableView <Item> tableviewLightMeals;
    @FXML private TableColumn<?, ?> colItemNumber;
    @FXML private TableColumn<?, ?> colItemName;
    @FXML private TableColumn<?, ?> colItemCategory;
    @FXML private TableColumn<?, ?> colItemPrice;
    @FXML private TableColumn<?, ?> colItemIngredients;
    ObservableList <Item> data = FXCollections.observableArrayList();

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        colItemNumber.setCellValueFactory(new PropertyValueFactory<>("itemid"));
        colItemName.setCellValueFactory(new PropertyValueFactory<>("itemname"));
        colItemCategory.setCellValueFactory(new PropertyValueFactory<>("itemcategory"));
        colItemPrice.setCellValueFactory(new PropertyValueFactory<>("itemprice"));
        colItemIngredients.setCellValueFactory(new PropertyValueFactory<>("itemingredients"));
        loadMenuItems();
    }

    public void loadMenuItems(){
            Connection con;
            try{
            String username = "register01";
            String password = "jxncjdshvbfdkhg";
            String url = "jdbc:mysql://mydatabaselink";
            con = DriverManager.getConnection(url, username, password);
            Statement sqlStat = con.createStatement();
            ResultSet rs = sqlStat.executeQuery("select * from menu where itemcategory='1'" + ";");
            while(rs.next()){
                data.add(new Item(
                rs.getInt("itemid"),
                rs.getString("itemname"),
                rs.getInt("itemcategory"),
                rs.getDouble("itemprice"),
                rs.getString("itemingredients")
                ));
            tableviewLightMeals.setItems(data);
                //System.out.println(ToStringBuilder.reflectionToString(Item));
            }
            sqlStat.close();
            rs.close();
          }catch(Exception e){
              e.printStackTrace();
              System.out.println("Error on Building Data");             
          }
    }
}

and this is my Item Class

public class Item {
    private int id;
    private String name;
    private int category;
    private double price;
    private String ingredients;

    public Item (int id, String name, int category, double price, String ingredients) {
        this.id = id;
        this.name = name;
        this.category = category;
        this.price = price;
        this.ingredients = ingredients;
    }

    public void setItemId (int id){
        this.id = id;
    }
    public void setItemName (String name){
        this.name = name;
    }
    public void setItemCategory (int category){
        this.category = category;
    }
    public void setItemPrice (double price){
        this.price = price;
    }
    public void setItemIngredients (String ingredients){
        this.ingredients = ingredients;
    }
    // Getters
    public int getItemId (){
        return id;
    }
    public String getItemName (){
        return name;
    }
    public int getItemCategory (){
        return category;
    }
    public double getItemPrice (){
        return price;
    }
    public String getItemIngredients (){
        return ingredients;
    }
}

I think my getters are right, as I have seen in another persons question on here and it is a very similar issue however I still have been unable to work it out.

Ben Sefton
  • 938
  • 6
  • 10

0 Answers0