Q:

javafx populate dynamic tableview from database with checkbox

I want to populate a dynamic tableview from database with 32 columns,First column contain the name of employee and remaining 31 columns for marking employee attendence from day1 to day31(checkbox).But I can able to populate tableview from database with 2 columns(name,checkbox) using get and set methods.Here is my code
    String sql ="SELECT * FROM attendence";
    pst =   (PreparedStatement) con.prepareStatement(sql);
    rs=pst.executeQuery();

        while (rs.next()) {
            //get string from db,whichever way 
            String name=rs.getString(3);
            int day=rs.getInt(6); 
            data.add(new User(name,day!=0)); //converting integer to boolean and storing on data(Observable list)
        }

         etname.setCellValueFactory(new PropertyValueFactory<>("name"));
         col.setCellValueFactory(new PropertyValueFactory<>("day1));

         col.setCellFactory(new Callback<TableColumn<User, Boolean>,       TableCell<User, Boolean>>() {

         public TableCell<User, Boolean> call(TableColumn<User, Boolean> p) {

            return new CheckBoxTableCell<User, Boolean>();

        }
          });

           jTable.getColumns().add(etname,col);
            jTable.setItems(data);
             }

This is User.java
   public class User {

      private final SimpleStringProperty ename;
      private BooleanProperty day1;

      User(String Ename,boolean day1)   
      {
        this.ename = new SimpleStringProperty(Ename);
        this.day1 = new SimpleBooleanProperty(day1);

        this.day1.addListener(new ChangeListener<Boolean>() {

            public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {

                System.out.println(enameProperty().get() + " invited: " + t1);
                System.out.println();
            }

        });            

    }

    public String getEname() {
        return ename.get();
      }

    public void setEname(String Ename) {
    ename.set(Ename);
   }

   public BooleanProperty day1Property() {
     return day1; 
    }

  public StringProperty enameProperty() {
    return ename;
    }

CheckBoxTableCell.java
 public class CheckBoxTableCell<S, T> extends TableCell<S, T> {

    private final CheckBox checkBox;

    private ObservableValue<T> ov;

    public CheckBoxTableCell() {

        this.checkBox = new CheckBox();

        this.checkBox.setAlignment(Pos.CENTER);

        setAlignment(Pos.CENTER);

        setGraphic(checkBox);

    } 

    @Override public void updateItem(T item, boolean empty) {

        super.updateItem(item, empty);

        if (empty) {

            setText(null);

            setGraphic(null);

        } else {

            setGraphic(checkBox);

            if (ov instanceof BooleanProperty) {

                checkBox.selectedProperty().unbindBidirectional((BooleanProperty) ov);

            }

            ov = getTableColumn().getCellObservableValue(getIndex());

            if (ov instanceof BooleanProperty) {

                checkBox.selectedProperty().bindBidirectional((BooleanProperty) ov);

            }

        }

    }

}

But no idea how i can do with 32 columns.
So i need a big help from anyone for my 2 problems.
1) How i can populate dynamic tableview from database with checkboxes 2) when i press a button should read all the names along with checkbox status(isSelected or not selected) like

jhon true true false ... .... 
rose false false true ... ..
george    true true true false

Answers will be appreciated.Thank you in advance.
 .. ..

A:

try with this code.   
  private static final List<String> groups = Arrays.asList("Group 1", "Group 2", "Group 3", "Group 4"); //declared an array

  TableView<AttributeRow> attributeTable = new TableView<>(); //new Table
   for (String group : groups) {  //Creating dynamic column
        TableColumn<AttributeRow, Boolean> groupColumn = new TableColumn<>(group);
        groupColumn.setCellFactory(CheckBoxTableCell.forTableColumn(groupColumn));
        groupColumn.setCellValueFactory(cellData -> cellData.getValue().activeProperty(group));
        attributeTable.getColumns().add(groupColumn);
    }

and AttributeRow class
class AttributeRow {

private final Map<String, BooleanProperty> activeByGroup = new HashMap<>();

public AttributeRow(List<String> companyGroups) {
    for (String group : companyGroups) {

        activeByGroup.put(group, new SimpleBooleanProperty()) ;
    }
}

public final BooleanProperty activeProperty(String group) {

    return activeByGroup.get(group) ;
}

 public final boolean isActive(String group) {
    return activeProperty(group).get();
}

public final void setActive(String group, boolean active) {
    activeProperty(group).set(active);
}

For loading checkbox data(true or false) we can use following method
         String sql ="SELECT * FROM attendence";
         pst =   (PreparedStatement) con.prepareStatement(sql);
         rs=pst.executeQuery();
         while (rs.next()) {

               AttributeRow row = new AttributeRow(groups);

               for(int j=0;j<5;j++) //here j<5 because array size =5
                           {
                               int i=j+6;
                            int day=rs.getInt(i); //getting Integer value(note:sqlite does not support boolean datatype so i stored as integer with 0 or 1)

                            row.setActive(day!=0); //converted into boolean useing day!=0
                           }
                            jTable.getItems().add(row);

               }

