0

I would like to find out if the column "KEY" from my "Settings" table has any value or not. If it has, the main function (Monitoring.start) should run, if not the Settings form should pop-up first (stage.show) and require for a fulfill.

    URL urlSettings = new File("src/main/java/com/svt/optimoo/Settings.fxml").toURL();
    Parent rootSettings = FXMLLoader.load(urlSettings);
    Stage stage = new Stage();
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.initStyle(StageStyle.DECORATED);
    stage.setResizable(false);
    stage.setTitle("Settings");
    stage.setScene(new Scene(rootSettings, 326, 216));

    if (Settings.COLUMN_KEY.isEmpty()) {
        final JPanel panel = new JPanel();
        JOptionPane.showMessageDialog(panel, "No data found in the given column!");
        stage.show();
    }
    else {
        Monitoring.start();
    }
  • The question is, how can i find out if the given column has any data or not, because that if statement that i wrote doesn't check anything and i am not sure if that's the way how I should do. – Dániel István Jun 12 '17 at 07:21
  • Probably the easiest way is to just run a count query on the table and check how many records are returned (zero indicating an empty table). – Tim Biegeleisen Jun 12 '17 at 07:21
  • 1
    Do you want to know if *Table is empty* or *given column has any data or not* ? That are two very different questions – Jens Jun 12 '17 at 07:22
  • Gonna try it. Thanks in advance! – Dániel István Jun 12 '17 at 07:22
  • @Jens Sorry i wasn't careful, I am interested if the given column has any value because if it has my second column will have to, and that's my whole table at the end. – Dániel István Jun 12 '17 at 07:25
  • 1
    @DánielIstván then improve your question please. write what you want to know if it is possible, add sample data and the expacted result – Jens Jun 12 '17 at 07:26
  • Dear @Jens let's say I have a table called (Cars) and it has two columns "KEY" and "VALUE". When you run your program you are trying to check if your KEY column has any data in your database or not, because if it is empty a form called "Settings" should pop-up where you should fulfill some data let's say "Colour" "Type" "Size" and so on. If the given column has already some data, the main function can be called. – Dániel István Jun 12 '17 at 07:34
  • @DánielIstván None of the code you show seems to relate to SQLite but if you want to know whether none of the KEY columns have data You run e.g. the SQL query `select count(KEY) from the_table_name where KEY != '' or KEY is not null; ` .and check whether the value it returns is > 0 – nos Jun 12 '17 at 07:59

0 Answers0