我的表格有两个字段:
我已经从上面的表格中将
当用户从
ProductID (Primary Key)
ProductName (duplicate values will be present)
我已经从上面的表格中将
productName
刷新到组合框中。当用户从
Combobox
中的产品列表中选择一个Item
时,我需要获取所选产品的相应ID。try {
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/kart","root","");
PreparedStatement statement=connection.prepareStatement("SELECT product_name,product_id from allproducts");
ResultSet result = statement.executeQuery();
while(result.next()){
combo.add(result.getString(1));
}
} catch (SQLException ec) {
System.out.println("Connection Failed! Check output console");
ec.printStackTrace();
return;
}