1
我有一個JComboBox,我必須顯示產品的名稱,並且每個代碼都有一個代碼, 在我的數據庫中,我必須註冊產品代碼,但在Combo中我必須顯示指定,我該怎麼做才能在組合中顯示指定,但將其代碼保存在數據庫中?在JComboBox中顯示屬性並註冊另一個屬性
這是我返回代碼和名稱
public ResultSet GetDesignation(JComboBox des)
{
ResultSet rs1 = null;
try {
conn=con.Connect();
stmt = conn.createStatement();
String rq1 = "SELECT designation, idproduit FROM produit";
rs1 = stmt.executeQuery(rq1);
while (rs1.next()) {
des.addItem(rs1.getString(1));
}
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally{
return rs1;
}
}
代碼,這是我得到的idproduct(代碼)的代碼
m.GetDesignation(des);
int designation=Integer.parseInt(des.getSelectedItem().toString());