我正在構建一個程序來檢查用戶的角色。當按鈕被按下時,它使用userID來查詢我們數據庫的角色/組表。如果一個人不在角色/組表中,那麼他們就是一個請求者。我有以下代碼,並想知道爲什麼最後的else if
語句不起作用。SQL查詢沒有結果我如何告訴用戶在我的程序中
當我們設置一個人作爲一個請求者時,他們被從角色/組表中刪除。所以resultset
應該是空的。對?
ResultSet rs = stmt.executeQuery(getRolesQuery2.toString());
try
{
boolean empty = true;
while (rs.next())
{
empty = false;
userRole = rs.getInt(1);
userGroup = rs.getInt(2);
System.out.println("The Users Current Role/Group is: " +userRole+ "/" +userGroup);
if(userRole == 4 && userGroup == 1)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " NDS Administrator");
}
else if(userRole == 1 && userGroup == 3)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " Privacy Administrator");
}
else if(userRole == 1 && userGroup == 5)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " Security Administrator");
}
else if(userRole == 1 && userGroup == 7)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " ORD Administrator");
}
else if(userRole == 1 && userGroup == 9)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " OEF-OIF Administrator");
}
else if(userRole == 1 && userGroup == 11)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " Surgery Administrator");
}
else if(userRole == 1 && userGroup == 13)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " Capri Administrator");
}
else if(userRole == 3 && userGroup == 15)
{
userRoleLbl.setText("The User Role/Group is: " +userRole+ "/" +userGroup+ " DART Super User");
}
//TODO: Add some handling for if the role/group is not present which means they are a requester
else if(empty)
{
userRoleLbl.setText("The User is a Requester");
}
}
在進入while循環時empty已被設置爲false,並且從未再次設置,因此if(empty)永遠不會爲true。 – JamesB
如果沒有結果,它會進入while循環嗎? – AFischbein
我遵循從接受的答案這裏的步驟:http://stackoverflow.com/questions/2938812/how-to-find-out-if-a-java-resultset-obtained-is-empty – DarthOpto