Results 1 to 5 of 5
- 01-04-2008, 11:36 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 28
- Rep Power
- 0
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
- 01-04-2008, 09:19 PM #2
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.
- 01-04-2008, 09:43 PM #3
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.
- 01-05-2008, 07:50 AM #4
Member
- Join Date
- Jan 2008
- Posts
- 5
- Rep Power
- 0
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
- 01-09-2008, 08:02 AM #5
Member
- Join Date
- Dec 2007
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
ZipOutputStream "duplicate entry"
By new_2_java in forum New To JavaReplies: 0Last Post: 02-14-2008, 04:28 PM -
Duplicate entry in registration form!!!
By anki1234 in forum Advanced JavaReplies: 1Last Post: 01-04-2008, 08:15 PM -
need help checking monthlyRate entry
By lowpro in forum New To JavaReplies: 1Last Post: 11-17-2007, 05:15 AM -
Help, created a username and password box
By cachi in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:21 AM -
JTextFields with username & password.
By Eric in forum AWT / SwingReplies: 2Last Post: 07-01-2007, 11:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks