Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

else loop not working

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
%>
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Baalu, for all our eyes' sake, please KeepItDown. It looks like you're shouting at us.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And BTW else is not a loop.
Please UseAMeaningfulSubjectLine.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic