有人可以告訴我,爲什麼一切工作正常,除了在表中顯示ID?數據類型有問題嗎?從DB的ID不顯示
有一個代碼,我把數據放到tableView中。
public class TabulkaProdukty {
private final FlowPane panelTabulky;
public final TableView<Produkty> tabulkaTabulkaProdukty;
public ObservableList<Produkty> dataTabulkaProdukty;
public static Connection connection;
private static Statement statement;
public TabulkaProdukty() {
panelTabulky = new FlowPane();
tabulkaTabulkaProdukty = new TableView<>();
panelTabulky.getChildren().add(tabulkaTabulkaProdukty);
tabulkaTabulkaProdukty.setEditable(true);
try {
connection = DriverManager.getConnection("jdbc:sqlite:produkty");
statement = connection.createStatement();
statement.executeUpdate("create table if not exists produkty(id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, nazev TEXT NOT NULL, popis TEXT NOT NULL, typ TEXT NOT NULL, cena TEXT NOT NULL);");
dataTabulkaProdukty = FXCollections.observableArrayList();
ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM produkty;");
while (rs.next()) {
dataTabulkaProdukty.add(new Produkty(rs.getInt("id"), rs.getString("nazev"), rs.getString("popis"), rs.getString("typ"), rs.getString("cena")));
}
// VECI V TABULCE
TableColumn idCol = new TableColumn("id");
idCol.setMinWidth(50);
idCol.setCellValueFactory(
new PropertyValueFactory<>("id"));
TableColumn nazevCol = new TableColumn("Název");
nazevCol.setMinWidth(100);
nazevCol.setCellValueFactory(
new PropertyValueFactory<>("nazev"));
TableColumn popisCol = new TableColumn("Popis");
popisCol.setMinWidth(200);
popisCol.setCellValueFactory(
new PropertyValueFactory<>("popis"));
TableColumn typCol = new TableColumn("Typ");
typCol.setMinWidth(50);
typCol.setCellValueFactory(
new PropertyValueFactory<>("typ"));
TableColumn cenaCol = new TableColumn("Cena");
cenaCol.setMinWidth(50);
cenaCol.setCellValueFactory(
new PropertyValueFactory<>("cena"));
tabulkaTabulkaProdukty.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tabulkaTabulkaProdukty.setItems(null);
tabulkaTabulkaProdukty.setItems(dataTabulkaProdukty);
tabulkaTabulkaProdukty.getColumns().addAll(idCol, nazevCol, popisCol, typCol, cenaCol);
} catch (Exception e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error dialog");
alert.setHeaderText("Chyba databáze");
alert.setContentText("Nepovedlo se načíst data z databáze.");
alert.showAndWait();
}
}
還有一類導航產品
public class Produkty implements Serializable {
private final SimpleIntegerProperty id;
private final SimpleStringProperty nazev;
private final SimpleStringProperty popis;
private final SimpleStringProperty typ;
private final SimpleStringProperty cena;
public NaMinimum panelNaMinimum;
public Produkty(int pID, String pNazev, String pPopis, String pTyp, String pCena) {
this.id = new SimpleIntegerProperty(pID);
this.nazev = new SimpleStringProperty(pNazev);
this.popis = new SimpleStringProperty(pPopis);
this.typ = new SimpleStringProperty(pTyp);
this.cena = new SimpleStringProperty(pCena);
}
public int getIDProduktu() {return id.get();}
public void setIDProduktu(int pID) {id.set(pID);}
public String getNazev() {return nazev.get();}
public void setNazev(String pNazev) {nazev.set(pNazev);}
public String getPopis() {return popis.get();}
public void setPopis(String pPopis) {popis.set(pPopis);}
public String getTyp() {return typ.get();}
public void setTyp(String pTyp) {typ.set(pTyp);}
public String getCena() {return cena.get();}
public void setCena(String pCena) {cena.set(pCena);}
}
我真的很感激解決的任何建議。
我說成問題 –