wood burning stoves 2.0*
The moose likes JSP and the fly likes how to recognise whether to do insert or update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "how to recognise whether to do insert or update" Watch "how to recognise whether to do insert or update" New topic
Author

how to recognise whether to do insert or update

Rishi Chopra
Ranch Hand

Joined: Mar 07, 2004
Posts: 108
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 ]

Life is Beautiful Learn to See it.........
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
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.


http://www.skillassert.com


 
GeeCON Prague 2014
 
subject: how to recognise whether to do insert or update