我使用php,因为我使用的java代码对我来说很难从数据库中检索信息并将它们添加到下拉列表中。我使用下面的函数检索它们,但我不知道如何将检索到的数据添加到下拉列表中。私人清单listOfTeams;
public void returnTeamListfromDB() {
listOfTeams = new ArrayList<DepartmentBean>();
Connection connection = DB.getCon();
try {
Statement statement = connection.createStatement();
/* select from the databse but in an ascending order ASC */
ResultSet result = statement.executeQuery("select department_id from departments order by department_id ASC");
while (result.next()) {
DepartmentBean department = new DepartmentBean();
String nameFromDB = result.getString("department_id");
int oya = Integer.parseInt(nameFromDB);
department.setId(oya);
/* add object to in the team list */
listOfTeams.add(department);
}
connection.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}