Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: compare form values with database values

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    hyderabad
    Posts
    9
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default compare form values with database values

    Hi,

    This is VaniRathna, i created a login page by using html and i have a table in database with user name and password
    my aim is only the persons who are in database are supposed to login but not other for that i wrote one class LoginAction and for DB connection i am using ibatis frame work, Logic_Build is my bean class where only setter & getters are there
    my code is

    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
     
    	        	/* ++++++++++++ DB logic +++++++++++++++ */
     
    				Reader reader=Resources.getResourceAsReader("Xml/SqlMapConfig.xml");
    				SqlMapClient sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);	
    				ArrayList lst=(ArrayList)sqlMap.queryForList("getAll",null);
    				Iterator itr=lst.iterator();
     
    				while(itr.hasNext())
    				{
    			         Object element = itr.next(); 
    			         System.out.print(element + " ");
    			         Logic_Build contact =(Logic_Build)element;
    					 LoginForm loginForm = (LoginForm) form;
    			         lst.size();
    			         for (int i = 0; i < lst.size(); i++) {
    			        System.out.println("|Name  = "+contact.getUser_name());
    			       System.out.println("|Password   = " + contact.getPassword());
    			         if ((loginForm.getUser_name().equals(contact.getUser_name()))&& (loginForm.getPassword().equals(contact.getPassword()))) 
    			         	{ 
    			        	 return mapping.findForward(SUCCESS);
    				        } 
    			        	 else {
    				            return mapping.findForward(FAILURE);
    				        }	
    			         }//for	
    				}//while


    please help me out this


    thanks in advance..
    VaniRathna


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    83
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: compare form values with database values

    Logic_Build is my bean class
    then you should create an object of bean as
    Logic_Build contact =(Logic_Build)form;
    not as
    Logic_Build contact =(Logic_Build)element;
    please mention where you accessed your database here??

  3. The Following User Says Thank You to arvindbis For This Useful Post:

    VaniRathna (October 24th, 2011)

  4. #3
    Junior Member
    Join Date
    Oct 2011
    Location
    hyderabad
    Posts
    9
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: compare form values with database values

    Quote Originally Posted by arvindbis View Post
    then you should create an object of bean as
    Logic_Build contact =(Logic_Build)form;
    not as


    please mention where you accessed your database here??


    Hi arvindbis

    Thank you for your help.
    I have a table (b_users) and for storing the values from DB i have Logic_Build bean class
    for retrieving form values i have LoginForm which is Form bean class. in my table i stored 4 rows with user_name and password. now i need to compare the form values with my DB values. but my code is checking only with first row. please help me to compare with all rows of DB
    my code is..

    /**
    * Program for comparing DB values with form values for login
    */


    public class LoginAction extends org.apache.struts.action.Action {

    private final static String SUCCESS = "success";
    private final static String FAILURE = "failure";
    HttpSession session=null;
    /* ++++++++++++execute method of ActionForward ++++++++++ */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    /* ++++++++++++ DB logic +++++++++++++++ */
    Reader reader=Resources.getResourceAsReader("Xml/SqlMapConfig.xml");
    SqlMapClient sqlMap=SqlMapClientBuilder.buildSqlMapClient(reade r);
    ArrayList lst=(ArrayList)sqlMap.queryForList("getAll",null);
    Iterator itr=lst.iterator();
    while(itr.hasNext())
    {
    Logic_Build contact =(Logic_Build)itr.next();
    LoginForm loginForm = (LoginForm) form;

    if ((loginForm.getUser_name().equals(contact.getUser_ name()))&& (loginForm.getPassword().equals(contact.getPasswor d())))
    {
    return mapping.findForward(SUCCESS);
    }
    else {
    return mapping.findForward(FAILURE);
    }
    }//while
    return mapping.findForward(SUCCESS);
    }//execute

    }



    thanks in advance
    VaniRathna

Similar Threads

  1. Character Values Inside of Number Values
    By bgroenks96 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 08:27 PM
  2. Using jbutton to write to jtextfield values to database
    By Sociopath in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 23rd, 2011, 10:53 PM
  3. Able to set, but not get values
    By Simple in forum What's Wrong With My Code?
    Replies: 18
    Last Post: June 23rd, 2010, 04:01 PM
  4. how to compare two set values
    By humdinger in forum Collections and Generics
    Replies: 1
    Last Post: March 13th, 2010, 10:46 AM
  5. Values of Input
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 8th, 2009, 02:46 AM