【发布时间】:2016-01-31 21:02:49
【问题描述】:
我正在尝试将数据从另一个类中的数据库传递到 jcombobox 中的 JFrame,但只显示最后一行。下面是一个示例代码:
A级...
public String jcbNames() {
try {
con = connCC.getDBconnection();
stm = con.createStatement();
ResultSet rs = stm.executeQuery("Select customerName From appointment");
while (rs.next()) {
customer = (rs.getString(1));
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
Logger.getLogger(Appointment.class.getName()).log(Level.SEVERE, null, ex);
}
return customer;
}
类 JFrame...
private void jCBCustomersActionPerformed(java.awt.event.ActionEvent evt) {
Appointment app = new Appointment();
this.jCBCustomers.removeAllItems();
this.jCBCustomers.addItem(app.jcbNames());
}
【问题讨论】:
-
您可能想看看How to Use Combo Boxes。但也请记住,您只返回来自
jcbNames的最后一个“客户”