my dog learned polymorphism*
The moose likes JDBC and the fly likes Database in table problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database in table problem" Watch "Database in table problem" New topic
Author

Database in table problem

Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
Scenario:
i have a table name children, fields are (PK,IDnumber,nameOfChild) - idnumber there is a foreign key.
for example idnumber = 222, which has 3 children. named lets say a,b,c so this is the table look like
children
PK IDnumber nameOfChild
1 222 a
2 222 b
3 222 c

in java i make a class Children with fields pk,idnumber,name

when i fetch it to the database, it looks like this
List<Chidlren> children = <e.g. the database will return the Children classes of IDnumber = 222>
now we have 3 classes, the children size is 3;
the problem is, when i edit the children making the children of 222 to 2? (e.g. a & b only because c is mistakenly inputted).
(remember that it is now in the database the a,b,c)

> will i delete the idnumber = 222 in the database, table name children?(e.g a,b,c) and add back the 2? is this correct or is there any better idea in doing
this.
> how will i tell the table named children that i want to delete the child c? (not the sql on deleting) i mean the approach to tell the database.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37976
    
  22
This question would sit better on our databases forum. Moving thread.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Roldan,
If you have a cascade delete set, deleting the parent row will delete the children.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database in table problem
 
Similar Threads
Delete from multiple tables.
Problem while writing Named Native Query
how to refer one table in second many times?
Update more than one rows through one Submit/Update Button
jsp: hidden field problem