my dog learned polymorphism*
The moose likes JDBC and the fly likes how to update a list of items? design question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to update a list of items? design question" Watch "how to update a list of items? design question" New topic
Author

how to update a list of items? design question

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi all,

I have a 2 tables with the following columns:
Table_A
IdA, Name

Table_B
IdB, IdA, car_number


say there's the following properties:
Table_A
IdA, Name
1 Toyota

Table_B
IdB, IdA, car_number
1 1 101
2 1 102
3 1 109
4 1 230
5 1 343
.
.

GUI: the data in table_b (the car_number) is given as textArea and the user write just numbers inside (100,101...)

Q: say the user returns to the textArea (data already existed in db and the user returns to edit/update the data) and made some changes example deleted number 101 and added 554 and 212

How can I make an UPDATE if I don't have the idBs (there are only numbers in the textArea)? *Assuming I can save an old version of the car_numbers with the idea, how do I still make an update?

thanks for any pointers
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Peter,
There are two approaches. You can save the ids in a map in memory. Or you can look up the id in the database based on car number.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
what if I do this:
I Delete all old info and Insert the new one. it will work but is there a trade off for that?
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

What other queries do you do against these tables? Because i do not see any reason of having separate ids for every car number.

Regarding delete and re-insert. You can try to add a columnt last, and do a simple update of records setting for new records last to 1 and for old to 0. If you have more records, then you had, then switch to insert mode. I do not see benefits of this approach, however it works in some of my systems.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to update a list of items? design question
 
Similar Threads
Accessing javabean method in onClick?
Which way to cope with concurrent access?
SQL question - get the first date from 2 tables
hibernate with postgres - deadlocks
Retreiving data from Table_A and at the same time inserting into Table_A