Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to recognise whether to do insert or update

 
Rishi Chopra
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

i have a page which puts five tabs on the body of a page each tab has a link to a different jsp page now what happens is first page is the one where i get a customer_id generated now when i click second tab and fill form and then on submitting i do a db insert using the customer_id from session .and so on continue with all tabs.
Now my problem is suppose after going to fourth tab with all the db inserts user clicks the second tabs and change some info and submits now wat happens is another record is inserted how do i recognise whether i should be doing update now
i tried out by first firing a select query using customer_id and if i get a count 0 then i will insert else i will update but now in a page there are 2 rows of records i can add more rows in that page now but how to recognise whether to do insert or update???


Regards
Rishi Chopra
[ September 20, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rishi, with 50 posts to the Ranch you should know by now that "hi" is a poor choice for a subject title. Please use subjects that describe your issue.

I've changed this one for you. Please read this for more information.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rishi Chopra:
but now in a page there are 2 rows of records i can add more rows in that page now but how to recognise whether to do insert or update?


Muliple rows per employee?
If so, what is the primary key for these rows of data?

As long as each has a unique identifier, you should be able to use the same logic that you used when adding/updating the employee.
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another easy way is delete all records in the tab_table pertaining to the customer_id and insert current tab_set records.

Warning: If part of the primary key in tab_table has a sequence (say of integer) or auto incrment column value and this functionality is used frequently, the sequence value may exceed the maximum limit specified for the column in the database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic