我必须将用户输入的ID与数据库ID进行比较,但我没有得到结果并且无法正确返回结果,并且无法使用以下代码执行此操作,请告诉我该怎么做
public String execute() throws Exception {
isValid = doProcessing(getUserid());
return SUCCESS;
}
public boolean doProcessing(String userid) throws Exception {
Connection con = null;
// ResultSet rs = null;
PreparedStatement pstmt = null;
boolean status=false;
try {
con = ConnectionDB.createConnection();
pstmt = con.prepareStatement("select userid from attestedform where userid=?");
pstmt.setString(1, userid);
ResultSet rs = pstmt.executeQuery();
request = ServletActionContext.getRequest();
session = request.getSession();
String s = (String) session.getAttribute("UsrBeanLoginId");
while (rs.next()) {
id = rs.getString("userid");
if (s.equalsIgnoreCase(id)) {
status = true;
}
else
{
status=false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
}
答案 0 :(得分:0)
您正在比较不同的价值。
我必须将用户输入的ID与数据库ID进行比较
更改您的代码
while (rs.next()) {
id = rs.getString("userid");
if (userid.equalsIgnoreCase(id)) {
status = true;
}
else
{
status=false;
}
}
答案 1 :(得分:0)
检查你的iterator.even迭代器找到了id in database
。仍然在迭代element.so,如果条件为真,请确保stop your iterator once
。
while (rs.next()) {
id = rs.getString("userid");
if (s.equalsIgnoreCase(id)) {
status = true;
//your COde Stop you iterator
}
else status=false;
}