| 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
|
|
|
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
|
|
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
|
|
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
|
 |
 |
|
|
subject: login code repeats error message
|
|
|