When I run the program it shows data for the ID, Month, and Time columns but not the DayOfWeek or DayOfMonth.
I can have additional code added upon request.
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Book a Lesson");
TableColumn<Schedule, Integer> ID = new TableColumn<>("ID");
ID.setMinWidth(80);
ID.setCellValueFactory(new PropertyValueFactory<>("ID"));
TableColumn<Schedule, String> dayOfWeek = new TableColumn<>("Day");
dayOfWeek.setMinWidth(80);
dayOfWeek.setCellValueFactory(new PropertyValueFactory<>("Day_of_Week"));
TableColumn<Schedule, String> Month = new TableColumn<>("Month");
Month.setMinWidth(80);
Month.setCellValueFactory(new PropertyValueFactory<>("Month"));
TableColumn<Schedule, String> dayOfMonth = new TableColumn<>("Date");
dayOfMonth.setMinWidth(80);
dayOfMonth.setCellValueFactory(new PropertyValueFactory<>("Day_of_Month"));
TableColumn<Schedule, String> time = new TableColumn<>("Time of lesson");
time.setMinWidth(80);
time.setCellValueFactory(new PropertyValueFactory<>("Time"));
TableColumn<Schedule, String> length = new TableColumn<>("Length of lesson");
length.setMinWidth(120);
length.setCellValueFactory(new PropertyValueFactory<>("Length_of_Lesson"));
table = new TableView<>();
table.setItems(getSchedule());
table.getColumns().addAll(ID,dayOfWeek,Month,dayOfMonth,time,length);
table.setMaxHeight(300);
This is the getSchedule() method:
public ObservableList<Schedule> getSchedule(){
ObservableList<Schedule> schedule = FXCollections.observableArrayList();
try {
Connection myConn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Database", "root", "Tsiknus41");
String query = "select * from Schedule";
// create a statement
PreparedStatement myStat = myConn.prepareStatement(query);
// execute a query
ResultSet rs;
rs = myStat.executeQuery();
while (rs.next()) {
schedule.add(
new Schedule(
rs.getInt("ID"),
rs.getString("Day_of_Week"),
rs.getString("Month"),
rs.getString("Day_of_Month"),
rs.getString("Time"),
rs.getString("Length_of_Lesson")
));
table.setItems(schedule);
}
myStat.close();
rs.close();
} catch (Exception ex) {
System.out.println("error");
}
return schedule;
}
And this the Schedule class with a constructor:
package USERS;
public class Schedule {
private int ID;
private String dayOfWeek;
private String month;
private String dayOfMonth;
private String time;
private String lengthOfLesson;
public Schedule( int iD, String DayOfWeek, String Month, String Day_of_Month, String Time, String Length_of_Lesson) {
this.ID = iD;
this.dayOfWeek = DayOfWeek;
this.month = Month;
this.dayOfMonth = Day_of_Month;
this.time = Time;
this.lengthOfLesson = Length_of_Lesson;
}
public String getDayOfWeek() {
return dayOfWeek;
}
public void setDayOfWeek(String dayOfWeek) {
this.dayOfWeek = dayOfWeek;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getDayOfMonth() {
return dayOfMonth;
}
public void setDayOfMonth(String dayOfMonth) {
this.dayOfMonth = dayOfMonth;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getLengthOfLesson() {
return lengthOfLesson;
}
public void setLengthOfLesson(String lengthOfLesson) {
this.lengthOfLesson = lengthOfLesson;
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
}
Ignore this, I am just writing this because it says my post is mostly code and needs more details.