我很努力地在数据库中获取名为'Names'的列的值。我还需要他们被分为Observabllelist
,所以我可以将它们用作choiceBox
中的选项。从数据库中获取名称并在java中使用它们在选择框中
@FXML
ObservableList GetTournamentsName() throws SQLException {
ObservableList<String> optionList = null;
Connection con = DBconnection.getConnection();
Statement st = con.createStatement();
String sql = ("SELECT Name FROM `tournaments`");
ResultSet rs = st.executeQuery(sql);
if (rs.next()) {
optionList = FXCollections.observableArrayList(rs.getString("Name"));
con.close();
}
return optionList;
}
,然后我将其分配给我从GetTournamentsName()
方法得到Choicbox TournamentsOption
的值初始化我的应用程序的场景。
@FXML
void initialize() throws SQLException {
TournamentsOption.setItems(GetTournamentsName());
}
该代码只是部分工作,我实际上得到表中的第一个名称,但不是所有其他的。这就是我所问的,我如何获得所有的价值? 非常感谢您的帮助!
optionList = FXCollections.observableArrayList(rs.getString(“Name”));这是什么? – Sedrick