This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes login code repeats error message Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 56201
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56201
    
  13

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: login code repeats error message
 
Similar Threads
Login Validation In JSP
SQL syntax error
Invalid user error message
Connection reset by peer:JVM_recv in socket input stream read
else loop not working