This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to write logic to insert multiple mappings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to write logic to insert multiple mappings" Watch "How to write logic to insert multiple mappings" New topic

How to write logic to insert multiple mappings

nalamati satyanarayana
Ranch Hand

Joined: Dec 16, 2005
Posts: 36
I am facing the problem like I am reading the table relations from xml file for example tale 1 has reference to table2 and table 3 ,table 2 has reference 5and 6 similaru table3 has reference to 7 and 8 here i need to write the logic to insert the following order like first i need to insert table 1 then i need to insert table followed table 5 and 6 next table2 followed by 7 and 8 table here i written the logic like beloe
but it is not working

for (int i = 0; i < (dbprofile.getProfile("export").getTables().getTable()).size(); i++)
flag = false;
Table table = dbprofile.getProfile("export").getTables().getTable().get(i);
for (int cons = 0; cons < table.getConstraints().getConstraint().size(); cons++)
Constraint constraint = table.getConstraints().getConstraint().get(cons);
if (constraint.getReference() == null )
flag = true;
if (cons == table.getConstraints().getConstraint().size() - 1 && flag == true)
{"<<<<<< Table name : >>>>>>>>"+table.getName());
if (tableIds == null)
tableIds = new StringBuilder();
} else
tableIds.append("," + table.getId().toString());
}// for cons
}// for i

canyone sujjest me
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Please UseCodeTags and punctuation. If I understand you correctly then you want to write the values from a xml-file to a database. Can't you just insert all the tables first and then add the relations? If not and the constraints are not ordered then you'll need to build a data-structure that houses the constraints and let's you extract the proper order of inserting them.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
I agree. Here's the link:
subject: How to write logic to insert multiple mappings
Similar Threads
insert problem to db2 tables from jsp page,please help very urgent
stuck up in the problem
Hibernate: Different Join in Save() and Get()
Returning a result set in an html form
populating a combo box