0

As the title says, I need more suggestions for proper implementation of retrieving and displaying data to a TableView in JavaFX 2.0.

I've seen this relevant question and its referring to use a DATAFX, but I cannot find tutorials on how can I implements it using a JDBC data source.

Please help I badly need it.


PS: I already have working codes (hard coded), but I'm still looking for a convenient way to do so.

Thanks in advance.

Community
  • 1
  • 1
AsirC
  • 449
  • 1
  • 6
  • 20

1 Answers1

0

Here is a working example:

public void start(Stage stage) throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");

    Scene scene =new Scene(new Group(),800,600);

    JdbcDataSource dataSource=new JdbcDataSource("jdbc:mysql://localhost:3306/mybasename?zeroDateTimeBehavior=convertToNull&user=username&password=userpassword", "clients", "descr");
    TableView tableView=new TableView();
    tableView.setItems(dataSource.getData());
    tableView.getColumns().addAll(dataSource.getColumns());
    ((Group)scene.getRoot()).getChildren().add(tableView);

    stage.setScene(scene);
    stage.show();
}
Jesse
  • 8,605
  • 7
  • 47
  • 57