• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

else loop not working

 
anu rani
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a program whatever i write the code in else loop it is not working.
String s = request.getParameter("username");
String pass=request.getParameter("password");
out.println("username"+"<br>"+s);
out.println("pass"+"<br>"+pass);
String pwd=null;
Statement st=null;
ResultSet rs=null;
Connection con=null;
ConnectionBean1 cb = new ConnectionBean1();
con = cb.getConnection();

String str="select password,status from login where username='"+ s +"' and password='"+pass+"' ";
out.println(str);
st =con.createStatement();
rs=st.executeQuery(str);

while (rs.next())
{
stat=rs.getString("status");
pwd=rs.getString("password");

}
out.println("stat"+stat);

out.println("pass"+pass);
out.println("pwd"+pwd);

rs.close();
st.close();
con.close();
if(pwd.equals(pass))
{
out.println("successfull login");
response.sendRedirect("../mobile4/view.jsp");
}
else
{
out.println("please try again");
response.sendRedirect("../mobile4/err.jsp");
}


}
catch(Exception exception)
{



out.println(exception.toString());
}
%>
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose, you give wrong username and password,then exception will occured here
right?

then you put yoour else block code into the Catch block.

Hope This Helps
 
baalu sasidhar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ARE U GETTING ANY EXCEPTIONS? IF YES CHECK WHAT EXCEPTION ARE U GETTING? LET ME KNOW WHETHER YOUR IF BLOCK IS WORKING?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Baalu, for all our eyes' sake, please KeepItDown. It looks like you're shouting at us.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And BTW else is not a loop.
Please UseAMeaningfulSubjectLine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic