I'm new. Let's say I want to create a TableView dynamically based on someString with a query like this:
TableView<???> table = new TableView<>();
ResultSet rs = statement.executeQuery("SELECT * FROM %s".formatted(someString));
So I will have various tables with various object types and therefore properties and columns
ResultSetMetaData meta = rs.getMetaData();
for (int i = 0; i < meta.getColumnCount(); i++) {
TableColumn<???, String> column = new TableColumn<>(meta.getColumnLabel(i + 1));
table.getColumns().add(column);
column.setCellValueFactory(data -> data.getValue().???dynamicPropertyBasedOn[i]);
}
while (rs.next()) {........}
How do I setCellValueFactory() not knowing the object type and exact number of columns beforehand?
I have models for my database tables, for basic example
Student.java:
public class Student {
private final StringProperty lastName;
private final StringProperty firstName;
private final IntegerProperty age;
// ...........
}
Schedule.java:
public class Schedule {
private final ObjectProperty<LocalDate> date;
private final BooleanProperty completed;
// ...........
}
I need to create TableViews of various objects with one function. Is it possible somehow?
TableView. Given that, why do you need to create the table columns dynamically based on the query? Or are you trying to generate aTableViewfrom any arbitrary SQL query? In which case, why have the specialized model classes?TableView<Student>, aTableView<Schedule>, and so on?TableView<Something>for every Object in db with all of their properties manually?TableView<String>and then create new Objects based on data I've got, or simply create models for every table and relatedTableView<Model>for every single one of them manually.