如何检查TableView中的列是否为主键(ResultSet)并使单元格不可编辑
如何检查使用 ResultSet 获取的列是否为主列,以及是否为主列,而不是使该列的单元格不可编辑。我使用 JavaFX。
我正在使用此代码,但它不起作用...谢谢!
ObservableList<String> column = FXCollections.observableArrayList();
HashSet<String> set = new HashSet();
DatabaseMetaData meta = conn.getMetaData();
tblTable.getColumns().clear();
ResultSet cols = meta.getColumns(comboDatabase.getValue(), null, cmbTable.getValue(), null);
ResultSet pk = meta.getPrimaryKeys(comboDatabase.getValue(), null,cmbTable.getValue());
while (pk.next()) {
String primarykey = pk.getString("COLUMN_NAME");
set.add(primarykey);
}
while (cols.next()) {
String name = cols.getString("COLUMN_NAME");
TableColumn col = new TableColumn(name);
column.add(name);
tblTable.getColumns().addAll(col);
if(set.contains(column)){
col.setCellFactory(TextFieldTableCell.forTableColumn());
col.setEditable(false);
tblTable.setEditable(true);
System.out.println("1");
}else{
col.setCellFactory(TextFieldTableCell.forTableColumn());
col.setEditable(true);
tblTable.setEditable(true);
System.out.println("2");
}
How is possible to check if a column taken using ResultSet is a primary or not and if it a Primary than to make cells of this column not editable.Im using JavaFX.
Im using this code but it doesn't work...Thank you!
ObservableList<String> column = FXCollections.observableArrayList();
HashSet<String> set = new HashSet();
DatabaseMetaData meta = conn.getMetaData();
tblTable.getColumns().clear();
ResultSet cols = meta.getColumns(comboDatabase.getValue(), null, cmbTable.getValue(), null);
ResultSet pk = meta.getPrimaryKeys(comboDatabase.getValue(), null,cmbTable.getValue());
while (pk.next()) {
String primarykey = pk.getString("COLUMN_NAME");
set.add(primarykey);
}
while (cols.next()) {
String name = cols.getString("COLUMN_NAME");
TableColumn col = new TableColumn(name);
column.add(name);
tblTable.getColumns().addAll(col);
if(set.contains(column)){
col.setCellFactory(TextFieldTableCell.forTableColumn());
col.setEditable(false);
tblTable.setEditable(true);
System.out.println("1");
}else{
col.setCellFactory(TextFieldTableCell.forTableColumn());
col.setEditable(true);
tblTable.setEditable(true);
System.out.println("2");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论