• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

how to recognise whether to do insert or update

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic