I want to display two column of my database into two JComboBox
我想将我的数据库的两列显示为两个JComboBox
String rq1 = "SELECT region FROM rg";
String rq2 = "SELECT ACTELS FROM rg";
st1 = conn.createStatement();
st2 = conn.createStatement();
rs1 = st1.executeQuery(rq1);
rs2 = st2.executeQuery(rq2);
comboBox_ACTELS = new JComboBox<String>();
comboBox_gouver = new JComboBox<String>();
while ((rs1.next())&&(rs2.next())) {
String m1= rs1.getString("region");
String m2= rs2.getString("ACTELS");
//comboBox_gouver.setModel(new DefaultComboBoxModel<String>(new String[] {m1}));
//comboBox_ACTELS.setModel(new DefaultComboBoxModel<String>(new String[] {m2}));
comboBox_gouver.addItem(m1);
comboBox_ACTELS.addItem(m2);
nbp ++;
}
1 个解决方案
#1
0
Opps, this can be done much simpler as both are from same table 'rg'
Opps,这可以做得更简单,因为两者都来自同一个表'rg'
String rq1 = "SELECT region,ACTELS FROM rg";
st1 = conn.createStatement();
rs1 = st1.executeQuery(rq1);
comboBox_ACTELS = new JComboBox<String>();
comboBox_gouver = new JComboBox<String>();
while (rs1.next()) {
String m1= rs1.getString("region");
String m2= rs1.getString("ACTELS");
//comboBox_gouver.setModel(new DefaultComboBoxModel<String>(new String[] {m1}));
//comboBox_ACTELS.setModel(new DefaultComboBoxModel<String>(new String[] {m2}));
comboBox_gouver.addItem(m1);
comboBox_ACTELS.addItem(m2);
nbp ++;
}
#1
0
Opps, this can be done much simpler as both are from same table 'rg'
Opps,这可以做得更简单,因为两者都来自同一个表'rg'
String rq1 = "SELECT region,ACTELS FROM rg";
st1 = conn.createStatement();
rs1 = st1.executeQuery(rq1);
comboBox_ACTELS = new JComboBox<String>();
comboBox_gouver = new JComboBox<String>();
while (rs1.next()) {
String m1= rs1.getString("region");
String m2= rs1.getString("ACTELS");
//comboBox_gouver.setModel(new DefaultComboBoxModel<String>(new String[] {m1}));
//comboBox_ACTELS.setModel(new DefaultComboBoxModel<String>(new String[] {m2}));
comboBox_gouver.addItem(m1);
comboBox_ACTELS.addItem(m2);
nbp ++;
}