1

I have been trying to populate a JavaFX TableView with data from mysql ResultSet. I have been searching for over a week now, before I stumbled on a similar question on this site JavaFX - Background Thread for SQL Query. The code there were a bit helpful, but the only issue I have with it is that the query selects a single column from the database.

What I need is to display a ResultSet from select * from tableName in a JavaFX TableView. I will greatly appreciate if any one can help me out with this.

Community
  • 1
  • 1
Iykon
  • 11
  • 1
  • Whats the problem to query more than one column using the same code? You can retrieve value from ResultSet by name `rs.getString("whatever_column_you_have_in_result_set");` and pass it to your model entity: `new MyModelEntity(retrievedValue1, retirevedValue2...)` and so on. – Alex Sep 22 '14 at 05:10
  • Adding to @SimY4 suggestion, JavaFX table cannot directly read a `resultSet`, so you gotta do it. You need to make an `ObservableList` from the `ResultSet` and set it to the data of the TableView, `table.setData(list)`. To know more about how data is set to a tableView, you can go through [this example](http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJABHGAJ). **If your model is `MyModelEntity` then your TableView must be of type `TableView`** – ItachiUchiha Sep 22 '14 at 05:48

1 Answers1

1

Hey I use these Example:

SwingWorker<Boolean, Integer> worker = new SwingWorker<Boolean, Integer>(){
             @Override
            /*
             * Note: do not update the GUI from within doInBackground.
             */
            protected Boolean doInBackground() throws Exception {
                boolean reqMess = true;
                do{
                }while(SOMETHINGHAPPEND);
                publish(); // with publish() you go to process
                return false;
            }
            @Override
            protected void process(List<Integer> chunks){
//update the gui frome here
            }

            @Override
            protected void done() {
                //if you want an last task before a quit do program it here
            }
         };  worker.execute();
    }

I think it is possible to update the table view by using the process funktion

xXTobiXx
  • 17
  • 5