我正在尝试从我的SQLite数据库中获取数据以显示在我的表视图中;但是,当我执行代码时,没有任何东西出现,我没有收到任何错误。我认为问题是“at”的返回值是值的位置而不是实际的字符串值。当我运行调试器时它会显示值,但是当我.addItem(at)返回的值是:[MAAT.ahtatable@ccc143f,MAAT.ahtatable @ 5b4f6e4b,MAAT.ahtatable @ 9623c2c,MAAT.ahtatable @ 59335ddd,MAAT.ahtatable @ 3532d728]
任何人都可以帮我解决这个问题
@Override
public void initialize(URL url, ResourceBundle rb) {
classCol.setCellValueFactory(
new PropertyValueFactory<ahtatable,String>("classification"));
thcCol.setCellValueFactory(
new PropertyValueFactory<ahtatable,String>("thc"));
capCol.setCellValueFactory(
new PropertyValueFactory<ahtatable,String>("capability"));
defCol.setCellValueFactory(
new PropertyValueFactory<ahtatable,String>("definition"));
scoreCol.setCellValueFactory(
new PropertyValueFactory<ahtatable,Integer>("score"));
objDbClass = new DBClass();
try{
con = objDbClass.getConnection();
buildData();
}catch (SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException ex) {
Logger.getLogger(MainScreenController.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void buildData(){
data = FXCollections.observableArrayList();
try{
String refresh = "SELECT * FROM HAZARD ORDER BY SCORE";
ResultSet rs = con.createStatement().executeQuery(refresh);
while(rs.next()){
ahtatable at = new ahtatable();
at.classified.set(rs.getString("CLASSIFICATION"));
at.htc.set(rs.getString("HTC"));
at.capability.set(rs.getString("EVENT"));
at.definition.set(rs.getString("DEFINITION"));
at.score.set(rs.getInt("SCORE"));
data.add(at);
}
AHTAtable.setItems(data);
System.out.println("table populated");
}catch (SQLException e) {
e.printStackTrace();
System.out.println("Error on Building Data");
}
}
package MAAT;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class ahtatable {
public SimpleStringProperty classified = new SimpleStringProperty();
public SimpleStringProperty htc = new SimpleStringProperty();
public SimpleStringProperty capability = new SimpleStringProperty();
public SimpleStringProperty definition = new SimpleStringProperty();
public SimpleIntegerProperty score = new SimpleIntegerProperty();
public String getclassified() {
return classified.get();
}
public String getdefinition() {
return definition.get();
}
public String gethtc() {
return htc.get();
}
public String getcapability() {
return capability.get();
}
public Integer getscore() {
return score.get();
}
}