我有一个像这样的 StageDAO 类:
public class Stage{
public int stageID;
public String label;
public Stage(ResultSet rs) {
try{
this.stageID=rs.getInt("StageID");
this.label=rs.getString("Label");
}
catch(Exception e){}
}
}
我在 StageDAO 类中有一个方法,我从数据库中获取数据,如下所示:
public class StageDAO{
Connect connectdb;
public StageDAO(Connect connectdb){
this.connectdb=connectdb;
}
public Vector retrieveAll() {
ResultSet lobjRS=null;
Vector lobjList=new Vector();
Connection lobjConnection = null;
Statement lobjStatement=null;
Stage lobjStage = null;
try{
lobjConnection = this.connectdb.getConnection();
lobjStatement = lobjConnection.createStatement();
lobjRS = lobjStatement.executeQuery(
"SELECT * FROM Stage order by sortkey");
while(lobjRS.next()){
lobjStage = new Stage (lobjRS);
lobjList.add(lobjStage);
}
}catch(){}
}
}
在我的 GUI 课上,我有这个:
StageDAO lobjStage= new StageDAO (connectdb);
Vector<Stage> stageList = lobjStage.retrieveAll();//Here i have the information
of stageID and stagelabel
private JComboBox lcbstage;
public void initialize(){
lcbstage= new JComboBox();
for(int i=0; i<stageList .size();i++){
lcbstage.addItem(stageList.get(i).label);
}
}
但是知道如果我在我的 Gui 中选择了 stage,我想知道 stageid。我不知道如何获取所选 stagelabel 的 stageid ?
谢谢您的帮助。