我正在制作礼服租赁系统,我只是想在每次选择特定场合时展示图片(婚礼,新娘派对,鸡尾酒会等) 并且有下面的项目列表。在这里,我只想在jcombobox中显示所有产品名称,无论何时选择和jcombobox中的项目,都会显示我保存在product_Barong表中的图片。先谢谢Godbless
Connection c = Connector.ConnectDB();
try {
String sql = "Select * From rental.product_barong" ;
pst = c.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
String item = rs.getString("ItemName") ;
itemcombo.addItem(item);
String list = itemcombo.getSelectedItem()+ " " ;
String sql2 = "Select Image from rental.product_barong WHERE ItemName = ? ";
pst = c.prepareStatement(sql2);
pst.setString(1, list);
pst.executeQuery();
byte[] img = rs.getBytes("Image") ;
ImageIcon image = new ImageIcon(img);
Image im = image.getImage();
Image myimg = im.getScaledInstance(Picture.getWidth(),
Picture.getHeight(), Image.SCALE_SMOOTH) ;
ImageIcon imgicn = new ImageIcon(myimg) ;
Picture.setIcon(imgicn);
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}