[英]How to turn the value into true of an if condition in java NetBeans?
I have an else if part coded inside the action perform method of a jButton to check whether the given E_ID's U_LEVEL is "Admin" or "User".Below is the code. 如果在jButton的动作执行方法内进行编码,则需要检查其他代码,以检查给定的E_ID的U_LEVEL是“ Admin”还是“ User”。下面是代码。
if (E_ID.getText().trim().length() == 0 | PWD.getPassword() == null) {
JOptionPane.showMessageDialog(null, "Username or Password cannot be blank", "Error", 0);
} else {
try {
ResultSet rs = new DBG1().getData("select * from USER where E_ID = '" +E_ID.getText() + "'");
Vector v = new Vector();
if (rs.next()) {
v.add(rs.getString(1));
}
if (v.isEmpty()) {
JOptionPane.showMessageDialog(null, "Invalid Username or Password", "Error", 0);
E_ID.setText("");
PWD.setText("");
E_ID.grabFocus();
} else {
ResultSet rs1 = new DBG1().getData("select * from USER where E_ID ='" + E_ID.getText() + "'");
while (rs1.next()) {
String type = (rs1.getString(2));
if (E_ID.getText().trim().equalsIgnoreCase(rs1.getString("E_ID")) && PWD.getText().equals(rs1.getString("PWD"))&& type.equals("Admin")) {//
// this.dispose();
new Home_Page(E_ID.getText()).setVisible(true);
} else if (E_ID.getText().trim().equalsIgnoreCase(rs1.getString("E_ID")) && PWD.getText().equals(rs1.getString("PWD")) && type.equals("User")) {
this.dispose();
new Home_Page(E_ID.getText()).setVisible(true);
}
else {
JOptionPane.showMessageDialog(null, "Invalid Username or Password", "Error", 0);
E_ID.setText("");
PWD.setText("");
E_ID.grabFocus();
}
}
this.dispose();
}
} catch (Exception e) {
System.out.println(e);
}
}
In above code there is an else-if. 上面的代码中有一个else-if。 in that if part,
在那部分
E_ID.getText().trim().equalsIgnoreCase(rs1.getString("E_ID"))
part and 部分和
PWD.getText().equals(rs1.getString("PWD"))
part retrieve a true value but 部分检索真实值,但
type.equals("Admin")
part retrieves a false value even though the MYSQL database "final_post" contains a table called USER in which there is a column called U_LEVEL under which I have saved the values "Admin" and "User". 即使MYSQL数据库“ final_post”包含一个名为USER的表,该部分仍会检索错误值。在该表中有一个名为U_LEVEL的列,在该列下我已保存了值“ Admin”和“ User”。
mysql> select * from USER;
+-------+-------+-----+------+
| E_ID | type | PWD | CPWD |
+-------+-------+-----+------+
| E/14 | Admin | qwe | qwe |
| SEC/1 | User | qw | qw |
+-------+-------+-----+------+
2 rows in set (0.04 sec)
I need to turn the value of 我需要改变
type.equals("Admin")
into true.Where should I make the amendments?Thanks in advance. 真的。我应该在哪里进行修改?谢谢。
I found where I should amend. 我找到了应该修改的地方。 In here the variable type refers to the column PWD of the table USER.
在这里,变量类型是指表USER的列PWD。 But I have compared it with the String "Admin".
但是我已经将其与字符串“ Admin”进行了比较。 That is why it had retrieved false value.
这就是为什么它检索了错误的值。 Once I corrected the column index the else if worked correctly.
一旦我更正了列索引,其他方法就可以正常工作。 :) String type = (rs1.getString(3));
:)字符串类型=(rs1.getString(3)); this should have String type = (rs1.getString(2));
这应该具有字符串类型=(rs1.getString(2)); That's all.
就这样。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.