-1
私はcostumerテーブルを持つmysql DBに2つのレコードが含まれています。id 1 name omar、id 3 name ahmad。 は、私が取得するには、このクラスを使用し、IDと名前を設定しmysqlの自動番号Jcomboboxの代わりにIDを値に追加
public class ComboItem
{
private int index;
private String name;
public ComboItem(int pindex, String pName)
{
this.index = pindex;
this.name = pName;
}
public int GetIndex()
{
return this.index;
}
public String GetName()
{
return this.name;
}
public void SetIndex(int pindex)
{
this.index = pindex;
}
public void SetName(String pName)
{
this.name = pName;
}
private void FillNameComboBox(JComboBox combo) throws IOException{
try{
combo.removeAllItems();
Connect c =new Connect();
Statement stmnt= c.MakeConnection().createStatement();
ResultSet rset=stmnt.executeQuery("select idCostumer,Name from Costumer");
while(rset.next()){
int index=Integer.parseInt(rset.getString("idCostumer"));
String name=rset.getString("Name");
ComboItem ci=new ComboItem(index, name);
combo.addItem(ci);
}
}
catch(SQLException e){
JOptionPane.showMessageDialog(NameComboBox, e);
}
}
私はそれが私のインデックスにないIDを与え続けてアプリを実行するたびに、メインクラス...私は何をすべき? screen shot