如何使用别名填充JavaFX中的TableView

时间:2019-03-06 18:33:30

标签: sqlite javafx

使用swing时,一切正常。

String sql= "SELECT idrepair as '№',"
        + "case when repairStatus in (0) then 'Not Done' "
        + "when repairStatus in (1) then 'Closed' "
        + "when repairStatus in (2) then 'Open' "
        + "else 'Unknown' end as  'Status'"
        + "FROM repairjournal";

我只想要使用JavaFX的新UI,所以这是我的代码,我会说我的努力:

    private void loadTableViewRepList(ObservableList oblist, Connection conn, TableView table) {
            oblist.clear();
            try {
                String sql = "SELECT * FROM repairjournal";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    oblist.add(new ModelTableRepairList(
                           rs.getString("idrepair"),
                           rs.getString("case when repairStatus in (0) then 'Not Done' "
               + "when repairStatus in (1) then 'Closed' "
               + "when repairStatus in (2) then 'Open' "
               + "else 'Unknown' end ")
                                       ));
                }
                table.setItems(oblist);
            } catch (SQLException ex) {
                Logger.getLogger(RepairListController
.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    private void loadTableViewRepList(ObservableList oblist, Connection conn, TableView table) {
                oblist.clear();
                try {
                    String sql = "SELECT idrepair, 
case when repairStatus in (0) then 
'Not Done.' when repairStatus in (1) then
 'Closed' when repairStatus in (2) then 'Open' 
                    else 'Unknown' end as 'Status' FROM repairjournal";
                    pst = conn.prepareStatement(sql);
                    rs = pst.executeQuery();
                    while (rs.next()) {
                        oblist.add(new ModelTableRepairList(
                               rs.getString("idrepair"),
                               rs.getString("repairStatus")
                                           ));
                    }
                    table.setItems(oblist);
                } catch (SQLException ex) {
                    Logger.getLogger(RepairListController
    .class.getName()).log(Level.SEVERE, null, ex);
                }
            }
  

主要错误是没有这样的列:'repairStatus'

有什么办法解决此问题吗?是的,我可以重命名数据,但是我在DB中有更多包含此类数据的表。

0 个答案:

没有答案