I'm trying to display database item into a JComboBox and this is my code.
public static void checkItemName(){
    Connection conn = SQLite.SQLite();
    String sql = "select itemname from item";
    try{
        Statement statement = conn.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()){
            String list = resultSet.getString("itemname");
            purcItemName.addItem(list);
            conn.close();
        }
    } catch (SQLException lol){
        System.out.println(lol.toString());
    }
}
I did declare static JComboBox purcItemName; and purcItemName = new JComboBox();
the method/function will be called then user press login button.
The problem I'm having now is that, it only show one item while my database has multiple item.
Anyone got item why?
Aucun commentaire:
Enregistrer un commentaire