Answer the question
In order to leave comments, you need to log in
How to pass the value of the fields from the database to the ChoiceBox?
I can't figure out how to correctly pass the value of the fields from the database table to the ChoiceBox.
The table has id and name
I use ORMLite.
In this way I get id and name:
@Test
public void testGetCategories() throws Exception {
CategoryService service = new CategoryService();
List<Category> list = service.getCategories();
Assert.assertNotNull(list);
for (Category category : list) {
System.out.println(category);
}
}
@DatabaseTable
public class Category {
@DatabaseField(generatedId = true)
private int id;
@DatabaseField
private String name;
public Category() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Category{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
public CategoryService() throws SQLException {
source = new JdbcConnectionSource(url);
dao = DaoManager.createDao(source, Category.class);
}
public List<Category> getCategories() throws SQLException {
return dao.queryForAll();
}
cbSubject.setItems(FXCollections.observable*****());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question