2017-07-28 74 views
0

我想从数据库返回的值中比较特定值。
我从STORESTAFF越来越多行,但是我想比较从表中返回的值之一..从Oracle数据库返回的多行中选择特定值

contains() and 
equals() 

不工作。

String qry = "Select all employe_id from storestaff where post='Admin'"; 
pstmnt = conn.prepareStatement(qry); 
ResultSet rs2 = pstmnt.executeQuery(qry); 
if (rs2.next()) { 
    String aa = rs2.getString("employe_id"); 

    if (aa.contains(UN.getText())) { 
     this.aa = aa; 
     JOptionPane.showMessageDialog(null, "Exists"); 
    } else { 
     JOptionPane.showMessageDialog(null, "Username doesn't Exist"); 
    } 
} 

任何人都可以建议我一个更好的解决方案,或可以告诉我更好的解决方案吗?

+0

耶的价值之一,我的prblm已解决 – Nancy

回答

0

如果使用if它会返回第一个值,你的情况,你必须使用while,其中环抛出所有的结果,所以你可以检查多个结果,而是可以使用:

boolean check = false; 
while (rs2.next()) { 
    String aa = rs2.getString("employe_id"); 
    if (aa.contains(UN.getText())) { 
     this.aa = aa; 
     check = true;//if the value exist change the variable to true 
     break;  //and break the loop 
    } 
} 

//when you end you have to check the value, if true then the user exist else no 
if (check) { 
    JOptionPane.showMessageDialog(null, "Exists"); 
} else { 
    JOptionPane.showMessageDialog(null, "Username doesn't Exist"); 
} 
+1

谢谢..我的问题解决了。 – Nancy

0

更改如果(rs2.next())为w 往往微不足道(rs2.next())你得到大量的数据,所以你需要遍历它来比较要

相关问题