Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2008, 01:36 PM
Member
 
Join Date: Dec 2007
Posts: 28
anki1234 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-04-2008, 11:19 PM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 11:43 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 09:50 AM
Member
 
Join Date: Jan 2008
Posts: 5
PortalTeam is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-09-2008, 10:02 AM
Member
 
Join Date: Dec 2007
Posts: 28
anki1234 is on a distinguished road
thanks buddy
i got it
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +3. The time now is 04:01 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org