I have a file universities.txt which looks like this:
Alabama Air University Alabama A&M University Alabama State University Concordia College-Selma Faulkner University Huntingdon College Jacksonville State University Judson College Miles College Oakwood College Samford University Southeastern Bible College Southern Christian University Spring Hill College Stillman College Talladega College University of North Alabama University of South Alabama University of West Alabama Alaska Alaska Bible College Alaska Pacific University Sheldon Jackson College University of Alaska - Anchorage University of Alaska - Fairbanks University of Alaska - Southeast Arizona American Indian College of the Assemblies of God Arizona State University Arizona State University East Arizona State University West DeVry University-Phoenix Embry-Riddle Aeronautical University Grand Canyon University Northcentral University Northern Arizona University
.. and so on, where in this case Alabama, Alaska and Arizona are locations and everything else are universities. What I want to do is load the location into a table called Location
and the Universities into a table called University
, where the Id
of the Location
table is a FK to the University
table, like this:
CREATE TABLE Location (
Id SERIAL PRIMARY KEY,
Name TEXT
);
CREATE TABLE University (
Id SERIAL PRIMARY KEY,
Location INTEGER REFERENCES Location (Id) NOT NULL,
Name TEXT
);
So what I want to do in Postgres is something like this:
for (int i=0 until i = universities.size() i++){
//each entry in the universities vector is a tuple with the first entry being the country/state
//and the second entry being a vector of the universities as String's
Vector tuple = (Vector)universities.get(i);
//insert into location table
String state = (String)tuple.get(0);
Vector u = (Vector)tuple.get(1);
for(int j=0; until j =u.size(); j++){
//insert into university table with i as FK to location table
Anyone knows how to do this?