0

I used php since the java code I used were bit difficult for me to retrieve the information from the database and add them to the drop down. I was retrieving them using the below function but I have no idea of how to add the retrieved data to the drop down list. private List 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();

    }
}
Geek Diva
  • 1
  • 1
  • can you add javascript tags.? It will help to understand the code more. And please mysql_connect under any loop is not good practice. Because you are using the same connection each time, then why you are trying to open that again and again? – Tanmay Vats Jun 13 '18 at 10:00
  • 1
    Add the Javascript `` and php `` tags, I can't tell from the code where the php starts and javascript starts – AntonyMN Jun 13 '18 at 10:03
  • Could you describe MySQL error in detail? What is error number? – SynapseIndia Jun 13 '18 at 10:29
  • 1
    probably you are mixing java (not javascript) and php. if there is no reason to mix up them, write all your code either in java or php, but not both. if you have a reason to do so, please show us the reason. – sj-i Jun 13 '18 at 11:00

0 Answers0