我希望能够从数据库中选择数据并使用comboBox显示它。java - 从数据库中检索数据并使用JcomboBox进行显示
我有以下代码,但它不显示在comboBox中的数据。我意识到有代码缺少显示数据和我的SQL语句不正确。我只是不确定我可以做任何建议,表示赞赏。
try { Statement st = db.con.createStatement(); (“SELECT Name,Size,Price FROM item WHERE Name =”+ comboBox_1.getToolkit());
JOptionPane.showMessageDialog(frame, "displayed");
while (rs.next()) {
String name = rs.getString("Name");
String size = rs.getString("size");
String price = rs.getString("price");
textArea_Name.append(name);
textArea_size.append(size);
textArea_price.append(price);
comboBox_1.addItem(rs.getString("Name"));
comboBox_1.getSelectedItem();
}}
catch (SQLException e) {
System.out.println("user not added");
e.printStackTrace();
}
}
});
所以...你尝试过什么? – 2012-02-17 16:29:16
您确实需要添加更多信息。你到目前为止有什么? – garyamorris 2012-02-17 16:31:02
使用JPA的示例显示在此处(http://stackoverflow.com/a/2531942/230513)。 – trashgod 2015-12-30 23:11:21