Home > Back-end >  Rookie help jcombox problem
Rookie help jcombox problem

Time:09-30

I define a public int a, use string after I get combox option, give a assignment, by a to achieve different functions, but I found that there are no assigned to a value, what should I do?
Combox. AddActionListener (new ActionListener () {
@ Override
Public void actionPerformed (an ActionEvent e) {
The String I=(String) combox. GetSelectedItem (). The toString ();
If (I=="administrator") {
Selete=1;
}
Else if (I=="employees") {
Selete=2;
}
}
});
This is a assignment after the implementation of different SQL statements
String SQL=null;
The database db1=new database (SQL);
If (selete==1) {
SQL="select loginname and password, the status from user_inf where loginname='" + +" usercode' and password='" + passcode + "' ";

} else if (selete==2) {
SQL="select name, password from employee_inf where name='" + +" usercode' and password='" + passcode + "' ";
}
SQL=run time error is null

CodePudding user response:

String comparison using equels
If you don't set up, so there was no selete values, the judgment is not established

CodePudding user response:

equals

CodePudding user response:

reference 1st floor xiaxiaolin_yun response:
string comparison using equels
If you don't set up, so there was no selete values, the judgment is not set up below

Using the equals or assigned a value

CodePudding user response:

Where is your selete defined?

CodePudding user response:

 

@ Override
Public void actionPerformed (an ActionEvent e) {
The String I=(String) combox. GetSelectedItem (). The toString ();
If (appropriate precautions quals (" administrator ")) {
Selete=1;
} else if (i. equals (" employees ")) {
Selete=2;
}
}


CodePudding user response:

You can use variable I first System. Out. The println (I); Print it out, to see what value, then the following. Equals, in front of the reference answer upstairs
  • Related