Sunday, January 29, 2017

How to set combobox value from database in java

How to set combobox value from database in java


-How to get data from database to JComboBox?
-L?y giá tr? t? database Hi?n th? lên comboBox! 
Java 2016
public ArrayList<Clazz> getArrayListLop() {
ArrayList<Clazz> list = new ArrayList();
try {
stmt = conn.prepareStatement("SELECT * FROM project.lop");
rs = stmt.executeQuery();
while (rs.next()) {
Clazz clazz = new Clazz(rs.getString("idlop"), rs.getString("lop"), rs.getString("idkhoa"),
rs.getString("khoahoc"));
list.add(clazz);
// Display comboBox set from databse
comboBox_lop.addItem(rs.getString("lop"));
}

} catch (Exception e) {
e.printStackTrace();
}

return list;
}


Available link for download