Results 1 to 5 of 5
  1. #1
    anki1234 is offline Member
    Join Date
    Dec 2007
    Posts
    28
    Rep Power
    0

    Default How to prevent duplicate username entry in database?

    Hi All,
    I have a application in struts framework which requires username password for login.If NewUser then I have a registration form to be filled by the user to register. The problem is that I am unable to stop duplicate values in the username field.I can do tat by making username as primary key in database but tat will not provide error information to user except providing error at server side.Can anybody tell me t way to do this.
    Thank u All
    ankit

  2. #2
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    well i dont know anything about JSP, but i know that in regular programming, to prevent added a duplicate object to a certain list, you can use a HashSet.

    Set<TypeName> list = new HashSet<TypeName>();
    list.add(whateverYouWantToAdd);

    If the use enters something duplicate, the hashset silently ignores this, and it is not added.

    I hope that helps.

  3. #3
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    You need to catch that exception in serverside and show that to client.

    Exception Handling in Struts

    You can use Ajax if you like to show error or avialiblity of username in real time..
    dont worry newbie, we got you covered.

  4. #4
    PortalTeam is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default

    I feel that u could try validating the user name with the database itself.
    Once when the user finishes the registration u can have the user name in the form bean and then inside the action classe's execute method u could do the validation of this new user name with that existing in database.(using the select count query).If the name already exist's the u redirect the user to the registration page with the msg notifying him that the name already exists.
    I think this will do .All the best

  5. #5
    anki1234 is offline Member
    Join Date
    Dec 2007
    Posts
    28
    Rep Power
    0

Similar Threads

  1. ZipOutputStream "duplicate entry"
    By new_2_java in forum New To Java
    Replies: 0
    Last Post: 02-14-2008, 05:28 PM
  2. Duplicate entry in registration form!!!
    By anki1234 in forum Advanced Java
    Replies: 1
    Last Post: 01-04-2008, 09:15 PM
  3. need help checking monthlyRate entry
    By lowpro in forum New To Java
    Replies: 1
    Last Post: 11-17-2007, 06:15 AM
  4. Help, created a username and password box
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:21 AM
  5. JTextFields with username & password.
    By Eric in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 12:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •