19 June 2016

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;
}

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang