我正在建立一个图书馆管理系统。我在问题表中将book_ID值设置为int。如何将它们添加到comboBox。每个学生都有他的名字上有多本书。我想添加comboBox来选择要在返还书类中使用的特定书籍。
JComboBox<Integer> bookID = new JComboBox<Integer>();
bookID.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
ArrayList<Integer> books = new ArrayList<Integer>();
String query = "SELECT Book_ID FROM Issue where Student_ID=?";
try {
pst = conn.prepareStatement(query);
rs = pst.executeQuery(query);
while(rs.next()){
int id = rs.getInt("Book_ID");
books.add(id);
}
rs.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// populate the combo box
DefaultComboBoxModel<Integer> model = new DefaultComboBoxModel<Integer>((Integer[]) books.toArray());
bookID.setModel(model);
}
});
bookID.setBounds(467, 53, 163, 26);
contentPane.add(bookID);