我想用在TextAria中输入的查询结果填充TableView 但是当我想将结果插入TableView时出现错误消息:输入
The method setItems(ObservableList<capture#3-of ?>) in the type TableView<capture#3-of ?> is not applicable for the arguments (ObservableList<ObservableList>)
@FXML
private Button button;
@FXML
private TextArea textAria;
@FXML
private TableView<?> jtable;
@FXML
public void Selection(ActionEvent e) {
try {
// declaration of the data that will contain the rows
ObservableList<ObservableList> data = FXCollections.observableArrayList();
// get query from the textAria
String query;
query = textAria.getText().toString();
// connect to database
Connection conn = DriverManager.getConnection(url, user, mdp);
Statement state = conn.createStatement();
ResultSet result = state.executeQuery(query);
ResultSetMetaData resultmeta = result.getMetaData();
String column;
for (int i = 0; i < resultmeta.getColumnCount(); i++) {
// We are using non property style for making dynamic table
final int j = i;
TableColumn col = new TableColumn(resultmeta.getColumnName(i + 1));
col.setCellValueFactory(
new Callback<CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
public ObservableValue<String> Call1(CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
jtable.getColumns().addAll(col);
jtable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
while (result.next()) {
// Iterate Row
ObservableList<String> row = FXCollections.observableArrayList();
for (i = 1; i <= resultmeta.getColumnCount(); i++) {
// Iterate Column
row.addAll(result.getString(i));
System.out.println("Row added " + row);
data.add(row);
}
}
// FINALLY ADDED TO TableView
jtable.setItems(data);
}
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}