我正在尝试填充JComboBox
,但没有填充来自数据库的数据。请帮助。
try {
String sql = "SELECT * FROM category WHERE category_name = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, (String)cmbCategory.getSelectedItem());
ResultSet rs = pstmt.executeQuery();
while(rs.next()) {
txtCategoryID.setText(rs.getString("category_id"));
}
conn.close();
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e);
}