aspose file tools*
The moose likes JDBC and the fly likes login code repeats error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "login code repeats error message" Watch "login code repeats error message" New topic
Author

login code repeats error message

jan frank
Greenhorn

Joined: Jul 31, 2005
Posts: 5
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?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

This is really not a JSP question so off to the JDBC forum we go.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

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.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
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.
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
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


Warm Regards<br />vikassheelgupta<br />9911005168
 
Don't get me started about those stupid light bulbs.
 
subject: login code repeats error message