首页 > 解决方案 > 我的 mySQL 数据库中的数据仅出现在所有其他列中

问题描述

当我运行程序时,它显示 ID、月份和时间列的数据,但不显示 DayOfWeek 或 DayOfMonth。

我可以根据要求添加其他代码。

@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);

这是 getSchedule() 方法:

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;

}

这是带有构造函数的 Schedule 类:

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;
}

}

忽略这一点,我只是写这个,因为它说我的帖子主要是代码,需要更多细节。

标签: javamysqljavafx

解决方案


推荐阅读