Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to update a list of items? design question

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic