<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page language="java" session="true" %>
		//Getting the text values from create login page
		String lid   = request.getParameter("loginid");
		String lpin  = request.getParameter("loginpin");
        String loginid  = lid.trim();
	    String loginpin = lpin.trim();
		out.println(loginpin);         // Connect to Database to retrive all the login id created and check if the Id already exist if it exist then redirect to login page again
		java.sql.Connection con;
        java.sql.Statement s;
        java.sql.ResultSet rs , rs1;

        String id  =  null;
		String pin =  null;
		int i=0;
        //Connecting Connetion String - passing the string to connect to db
		String connectionURL = "jdbc:sqlserver://localhost:1433;databaseName=Admissions;integratedSecurity=true;selectMethod=cursor";

               con = java.sql.DriverManager.getConnection(connectionURL);
              // out.println("1");
		catch(ClassNotFoundException cnfex)

		String sql = "select * from Login where userID='"+loginid+"'";
				s = con.createStatement();
				rs = s.executeQuery(sql);
		while( rs.next() )
		     pin = rs.getString("userPin");
			 id  = rs.getString("userID");

		if(loginid.equals(id) && loginpin.equals(pin))
		  out.println("login successful");
           out.println("incorrect username/password combination");
    	catch(Exception e){e.printStackTrace();}
		if(rs!=null) rs.close();
		if(s!=null) s.close();
		if(con!=null) con.close();


When I execute this code its not allowing valid login and password.
i tried printing the values to see if its comparing wrong values but the same values are being displayed. i think the if statement is not working fine. does any one know what could be the problem with the if statement or any other possible problem,....

Recommended Answers

All 4 Replies

Hello thank you so much for your suggestion ...I really appreciate it .. I went through the MVC example ,but i do not know java beans and servlets . More over i am very curious to know whats wrong with the code i wrote here


Just try to use trim() for id and pin i.e when retrieving from database and then compare with loginid and loginpin.

I hope it solves the problem.

Thank you so much Deepali... It worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.