I'm pretty new to JavaFX, and also not incredibly familiar with using databases in Java in general, but I have to convert an existing JavaFX program I made to remove a list that is populating a TableView table and replace it with items from a database and giving the user the ability to add or delete as well. This is essentially a very simplified version of a course registration program for a student. Everything works as it is, I just need to use a database so that a faculty side can be used to view which students are registered for which classes. I'm just not familiar with the best way to call the database and apply it to the tableView. I want to be able to select a row on the table, click my action button and register that student. Any help is greatly appreciated.
Code:
public class Screen3Controller implements Initializable {
@FXML private Button continuebtn;
@FXML private Button studAddCrseBtn;
@FXML private Button yesBtn;
@FXML private Label regStatus;
@FXML private TableView<SummerClass> table;
@FXML private TableColumn<SummerClass, Integer> id;
@FXML private TableColumn<SummerClass, String> dept;
@FXML private TableColumn<SummerClass,Integer> number;
@FXML private TableColumn<SummerClass, String> title;
@FXML private TableColumn<SummerClass, String> day;
@FXML private TableColumn<SummerClass, String> time;
@FXML private TableColumn<SummerClass, Boolean> checkbox;
private ObservableSet<CheckBox> selectedCheckBoxes = FXCollections.observableSet();
private ObservableSet<CheckBox> unselectedCheckBoxes = FXCollections.observableSet();
private IntegerBinding numCheckBoxesSelected = Bindings.size(selectedCheckBoxes);
@FXML
private IntegerProperty index = new SimpleIntegerProperty();
private final int maxNumSelected = 3;
public ObservableList<SummerClass> list1 = FXCollections.observableArrayList(
new SummerClass (10001, "ACCT", 1010 , "Intro to Acct (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10002, "ACCT", 2010 , "Acct for Bus. (3)", "MWF", "9:00 - 10:15" ),
new SummerClass (10003, "ART", 1010 , "Fund. of Art (3)", "TR", "3:00 - 4:15" ),
new SummerClass (10004, "ART", 1110 , "Art History (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10005, "BIOL", 1010 , "Principles of Biology I (3)", "TR", "9:00 - 10:15" ),
new SummerClass (10006, "BIOL", 2010 , "Principles of Biology II (3)", "MWF", "3:00 - 4:15" ),
new SummerClass (10007, "CHEM", 1010 , "Principles of Chemistry I (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10008, "CHEM", 2010 , "Principles of Chemistry II (3)", "TR", "9:00 - 10:15" ),
new SummerClass (10009, "CPSC", 1010 , "Java I (3)", "TR", "3:00 - 4:15" ),
new SummerClass (10010, "CPSC", 2010 , "Java II (3)", "MWF", "9:00 - 10:15" ),
new SummerClass (10011, "ENGL", 1010 , "Composition I (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10012, "ENGL", 2010 , "Composition II (3)", "TR", "3:00 - 4:15" ),
new SummerClass (10013, "FIN", 1010 , "Principles of Finance I (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10014, "FIN", 2010 , "Principles of Finance II (3)", "TR", "9:00 - 10:15" ),
new SummerClass (10015, "GEO", 1010 , "Intro to Geology (3)", "MWF", "3:00 - 4:15" ),
new SummerClass (10016, "GEO", 3610 , "Geology in History (3)", "TR", "1:00 - 2:15" ),
new SummerClass (10017, "HIST", 1210 , "Western History (3)", "MWF", "9:00 - 10:15" ),
new SummerClass (10018, "HIST", 1510 , "Fund. of History (3)", "MWF", "3:00 - 4:15" ),
new SummerClass (10019, "MATH", 1010 , "Elementary Algebra (3)", "TR", "1:00 - 2:15" ),
new SummerClass (10020, "MATH", 2010 , "Linear Algebra (3)", "MWF", "9:00 - 10:15" ),
new SummerClass (10021, "NUTR", 1010 , "Nutrition Fundamentals (3)", "TR", "3:00 - 4:15" ),
new SummerClass (10022, "PHYS", 1010 , "Intro to Physics (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10023, "PHYS", 2010 , "Physics II (3)", "MWF", "9:00 - 10:15" ),
new SummerClass (10024, "POL", 1010 , "Political Science I (3)", "TR", "3:00 - 4:15" ),
new SummerClass (10025, "POL", 1010 , "Political Science II (3)", "MWF", "1:00 - 2:15" ),
new SummerClass (10026, "STEM", 1010 , "Stem Education I (3)", "TR", "9:00 - 10:15" ),
new SummerClass (10027, "STEM", 2010 , "Advanced Stem Education (3)", "TR", "3:00 - 4:15" ),
new SummerClass (10028, "STEM", 3010 , "Stem Education in Business (3)", "MWF", "1:00 - 2:15" ));
final ObservableList<SummerClass> list2 = FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
id.setCellValueFactory(new PropertyValueFactory<>("id"));
dept.setCellValueFactory(new PropertyValueFactory<>("dept"));
number.setCellValueFactory(new PropertyValueFactory<>("number"));
title.setCellValueFactory(new PropertyValueFactory<>("title"));
day.setCellValueFactory(new PropertyValueFactory<>("day"));
time.setCellValueFactory(new PropertyValueFactory<>("time"));
checkbox.setCellValueFactory(new PropertyValueFactory<SummerClass, Boolean>(""));
checkbox.setCellFactory(new Callback<TableColumn<SummerClass, Boolean>, TableCell<SummerClass, Boolean>>(){
public TableCell<SummerClass, Boolean> call(TableColumn<SummerClass, Boolean> p){
return new CheckBoxTableCell<SummerClass, Boolean>();
}