0
我從mysql數據庫填充我的tableview,但只有列ID是唯一填充的。只有一個列填充在我的Tableview中
我的主:
public void populate() throws Exception{
ObservableList<userdata1> data = FXCollections.observableArrayList();
tableView();
try{
String query = "select * from members";
ps = new Connect().connectDatabase1();
rs = ps.executeQuery(query);
while(rs.next()){
data.add(new userdata1(rs.getInt(1),rs.getString(2),rs.getInt(3)));
tblView.setItems(data);
}
}catch(Exception e){
System.out.print("asdqweasd");
}
}
public void tableView()throws Exception{
tblView.getItems().clear();
tblView.getColumns().clear();
rs = ps.executeQuery("SELECT * FROM members");
ObservableList<userdata1> data = FXCollections.observableArrayList();
TableColumn column1 = new TableColumn("ID");
column1.setMinWidth(85);
column1.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("ID"));
TableColumn column2 = new TableColumn("Name");
column2.setMinWidth(565);
column2.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("comp_name"));
TableColumn column3 = new TableColumn("STATUS");
column3.setMinWidth(123);
column3.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("mem_status"));
tblView.getColumns().addAll(column1,column2,column3);
}
我userdata1:
public class userdata1 {
public SimpleIntegerProperty ID;
public SimpleStringProperty comp_name;
public SimpleIntegerProperty mem_status;
public userdata1(Integer id, String comp_name, Integer mem_status){
this.ID = new SimpleIntegerProperty(id);
this.comp_name = new SimpleStringProperty(comp_name);
this.mem_status = new SimpleIntegerProperty(mem_status);
}
public Integer getID() {
return ID.get();
}
public String getcomp_name(){
return comp_name.get();
}
public Integer getmem_status() {
return mem_status.get();
}
public void setID(Integer id) {
this.ID.set(id);
}
public void setcomp_name(String comp_name) {
this.comp_name.set(comp_name);
}
public void setmem_status(Integer mem_status) {
this.mem_status.set(mem_status);
}
}
數據mem_status和COMP_NAME不填充它們各自的列
謝謝你..我消氣的首字母大寫的約定是唯一的問題.. :) )我真的很感謝你的回答..謝謝你非常多:) –
我只是認爲在我的getComp_Name中使用下劃線不會是在getter中的問題,但它似乎下劃線被讀爲任何單詞的連接符,並將其作爲一個.. (糾正我,如果即時通訊錯誤使用這些條款),所以更改getComp_Name getComp_name是解決這個問題。 tnx再次夥計 –