This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

registeration process logic

 
hesham katon
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All

I am doing registeration process
there is 2 tables
1. client
2. serial (has a field with last client no.)

I want to add new client in client table , its number is last client no. +1

what i already did as follows

1. html form for user information
2. jsp confirmation page (gets data from the previous page)
it access serial table and gets last client no.
it has submit button that add new client to client table
3. jsp page to modify serail table with the new customer no

this works fine when single user test it

but when many user try to register an error happen
because the second step is wrong , may be 2 or more clients gets the same last clien no. , and then when they submit a duplication may happen

i want to know a better logic for this problem

Thank you all in advance
 
Rahul Kappor
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure what database you are using but I would recommend that use sequence (Oracle has sequence) to get the next number before you insert into the table. Sequence will always assign next available number to new request even when there are concurrent request to db at the same time. Oracle will handle that far you.

Your issue is that there could be multiple clients who can access the page that assign the next number at the same time.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by hesham katon:

2. jsp confirmation page (gets data from the previous page)
Not the best of ideas. JSP should be used for views and not for processing. You might find this article helpful.

3. jsp page to modify serail table with the new customer no
See above.

this works fine when single user test it

Most often, when things go awry when multiple users start using a web app it's because of thread safety issues.

Be sure that you have no instance variables in your servlets or JSPs. The use of <%! %> on a JSP is the easiest way to get yourself into big trouble.

[ November 11, 2007: Message edited by: Bear Bibeault ]
[ November 11, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic