S
S
striver2019-03-02 22:36:28
SQLite
striver, 2019-03-02 22:36:28

JavaFx populating a table using case from sqlite database. Is it possible to?

There is an application on SWING, the data is uploaded to the table, while the data from one column changes depending on the conditions:

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

I would like the same but on FX, however, I can’t figure out where to shove the case. Below option throws an error
SQLException: no such column: 'case when repairStatus in (0)

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TheAndrey7, 2019-03-03
@TheAndrey7

ResultSet.getString()as an argument, it can only take the index of a column in the result set or its name. There are no requests there. Read the javadoc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question