You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX表格仅显示部分MySQL数据:ID/Month/Time正常,DayOfWeek等列无数据

Troubleshooting Your Two Technical Issues

Hey there! Let's break down your two technical problems and walk through possible fixes for each:

1. MySQL Data Only Displays Every Other Column

First up, the issue where your MySQL data is showing only every other column. Here are the most common culprits and how to check them:

  • Check your SELECT query: If you're explicitly listing columns (like SELECT id, month, time FROM schedule), double-check that you haven't accidentally omitted every other column. Try running SELECT * FROM your_table_name instead to see if all columns appear—this will rule out a query-related mistake.
  • Client display settings: If you're using a tool like MySQL Workbench or phpMyAdmin, make sure you haven't hidden any columns. Look for a "Columns" menu or right-click the table header to verify all columns are set to show.
  • Table structure and data integrity: Run DESCRIBE your_table_name; to confirm all columns exist in the table. Then check if the missing columns actually have data—if they're all NULL, some clients might hide them by default, or your data insertion logic might be skipping those columns.

2. JavaFX Table Missing DayOfWeek & DayOfMonth Data

For your JavaFX table issue where ID, Month, and Time show up but DayOfWeek and DayOfMonth don't, let's focus on the most likely fixes based on the code snippet you shared:

Key Checks to Perform:

  • Verify PropertyValueFactory setup: Your ID column uses new PropertyValueFactory<>("ID")—make sure you've completed the setup for the missing columns exactly like this. For example:

    // Complete setup for DayOfWeek column
    TableColumn<Schedule, String> dayOfWeekCol = new TableColumn<>("DayOfWeek");
    dayOfWeekCol.setMinWidth(120);
    dayOfWeekCol.setCellValueFactory(new PropertyValueFactory<>("dayOfWeek"));
    
    // Complete setup for DayOfMonth column
    TableColumn<Schedule, Integer> dayOfMonthCol = new TableColumn<>("DayOfMonth");
    dayOfMonthCol.setMinWidth(100);
    dayOfMonthCol.setCellValueFactory(new PropertyValueFactory<>("dayOfMonth"));
    

    Important: The string inside PropertyValueFactory (like "dayOfWeek") must exactly match the property name in your Schedule class (case-sensitive!).

  • Ensure Schedule class has proper getters: PropertyValueFactory relies on standard JavaBean getter methods. Your Schedule class must have these (adjust types based on your actual data):

    public class Schedule {
        // Your existing fields
        private Integer ID;
        private String month;
        private String time;
        private String dayOfWeek;
        private Integer dayOfMonth;
    
        // Existing getters
        public Integer getID() { return ID; }
        public String getMonth() { return month; }
        public String getTime() { return time; }
    
        // Required getters for missing columns
        public String getDayOfWeek() { return dayOfWeek; }
        public Integer getDayOfMonth() { return dayOfMonth; }
    
        // Optional: If using JavaFX Properties, add these too
        public StringProperty dayOfWeekProperty() { /* Implement with SimpleStringProperty */ }
        public IntegerProperty dayOfMonthProperty() { /* Implement with SimpleIntegerProperty */ }
    }
    
  • Confirm data is present in Schedule objects: Before passing your ObservableList<Schedule> to the table, log or debug the dayOfWeek and dayOfMonth values of each object. If they're NULL, the issue is with how you're fetching data from MySQL, not the JavaFX table itself. Double-check your database query and data mapping code to ensure those values are being pulled correctly.

内容的提问来源于stack exchange,提问作者Jay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:47:30