java - Login verification using database -


When the logged in user is present in the database, if runs the result, but When it 't, and are not part Why?

This is my code.

  string thisname = request.getParameter ("user name"); String HypWD = Request.GetPamator ("password"); // Question to choose the user's name and password from the database. String Query = "Choose from Login, where Username =?";; Pstmt = (generated location) con.prepareStatement (query); Pstmt.setString (1, thisname); Res = pstmt.executeQuery (); While (res.next ()) {System.out.println ("hhh"); If ((thisname.equals (res.getstring ("username")) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; (res.getString ("password")) {System.out.println ("hello") ;} And {System.out.println ("in"); session.invalidate (); response.sendRedirect ("index.html");}}  

< The reason for this is that if the logged in user is not present then res.next () is always false. Return and control will never go inside. So there is no use of else in your code.

Use the modified code below Try:

  string name = request.getParameter ("user name"); string hwewd = request.gate parameter ("password"); // to select user's name and password from database Question: String query = "Select from Login, where username =?"; Pstmt = (generated location) con.prepareStatement (query); Pstmt.setString (1, thisname); Res = pstmt.executeQuery (); If (res.next ()) {System.out.println ("hhh"); If ((thisname.equals (res.getstring ("username")) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; (res.getString ("password")) {System.out.println ("hello") ;}} And {System.out.println ("in"); session.invalidate (); response.sendRedirect ("index.html");}  

and tell me that this How does it go?


Comments