• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

login code repeats error message

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,

I have this piece of login code for a webpage that words like a charm IF there's only one username in the database table that the website is connected to.

If there are 3 usernames in the database table AND the username & password of the website is incorrect, then the error message is replicated THREE times!!

"Login Failed.Please try Again Login Failed.Please try Again Login Failed.Please try Again."

If there are 4 usernames in the database table and the username and password on trying to log in from the website is incorrect, then the error message is replicated FOUR times...and so on.

Any ideas?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is really not a JSP question so off to the JDBC forum we go.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's doing exactly what you told it to:



You are selecting all the usernames and passwords from the table and then looping over them all.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
You are selecting all the usernames and passwords from the table and then looping over them all.


In other words, look into adding a where clause and seeing if any rows are returned rather than looping through them all.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are displaying the failure message in the Resultset loop, so it is displaying for each resultset row, which is not meeting your if condition, try to put the message out of the loop only once, by using any boolean variable.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con=DriverManager.getConnection("your driver & port realtedinformateion");
uname=request.getParameter("uname");
upassword=request.getParameter("upassword");

sql="select * from login where acc0='"+uname+"' and acc1='"+upassword+ "' ";
st=con.createStatement();
rs=st.executeQuery(sql);
if(rs.next())
{
response.sendRedirect("dod_auth.jsp");
session.setAttribute("username",uname);
}
else
{
response.sendRedirect("login.jsp?status='failed'");
}

}catch(Exception e)
{
System.out.println("A SQL error is generated :"+e);
}

this will help u alot fine
and dont for get to use Exception
 
He does not suffer fools gladly. But this tiny ad does:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic