我在连接三个jComboBox时遇到了一些麻烦。 我可以链接两个组合框,但是当我尝试链接三个组合框时,我遇到了问题。
所以我在MySQL中有数据库,我试图链接三个表,例如:
我是讲师,我需要获得一个小组名单,
正如我所说,我用两个组合框完成了它。这是我的代码:
public void Fakultetas(){
String SQL="select * from fakultetas;";
String reiksmes[]=new String[2];
try{
conn.Connection();
conn.stt=conn.conec1.createStatement();
conn.rtt=conn.stt.executeQuery(SQL);
while (conn.rtt.next()){
reiksmes[0]=conn.rtt.getString(1);
reiksmes[1]=conn.rtt.getString(3);
jComboBox1.addItem(reiksmes[0]+"-"+reiksmes[1]);
}
}catch(Exception e){
JOptionPane.showMessageDialog(this, e.toString());
}
}
private void StudijuPrograma(){
if (jComboBox1.getSelectedIndex()>0){
String SQL="select * from studijuprograma where FakultetoID=";
SQL+="'"+jComboBox1.getSelectedItem().toString()+"'";
String reiksmes[]=new String[1];
try{
conn.Connection();
conn.stt=conn.conec1.createStatement();
conn.rtt=conn.stt.executeQuery(SQL);
while (conn.rtt.next()){
reiksmes[0]=conn.rtt.getString(3);
jComboBox2.addItem(reiksmes[0]);
}
}catch(Exception e){
JOptionPane.showMessageDialog(this, e.toString());
}
}
}
private void Grupes(){
if (jComboBox2.getSelectedIndex()>0){
String SQL="select * from grupė where ProgramosID=";
SQL+="'"+jComboBox2.getSelectedItem().toString()+"'";
String reiksmes[]=new String[1];
try{
conn.Connection();
conn.stt=conn.conec1.createStatement();
conn.rtt=conn.stt.executeQuery(SQL);
while (conn.rtt.next()){
reiksmes[0]=conn.rtt.getString(1);
jComboBox3.addItem(reiksmes[0]);
}
}catch(Exception e){
JOptionPane.showMessageDialog(this, e.toString());
}
}
}
我无法连接第三个组合框。它不起作用,没有任何价值。前两个组合框完美无缺。