GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Retrieving Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Retrieving Collection" Watch "Retrieving Collection" New topic
Author

Retrieving Collection

Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
I have a domain object(profile) holding array of different objects as below.

profile have school[], experience[], etc.

I want to retrieve only school[].

Could some one help on the same.

Thanks,

Ananth
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
I tried declaring an arraylist and tried to populate the data from education[] from profile object.

Could someone give me some tip on retrieving the same.

Thanks in advance,

Ananth
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
You need to provide more detail before anyone can understand your question. Give us some information on how the data is related, what code you created to retrieve, what "didn't work" about it, etc - then you'll probably get some good responses.
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
public Profile getProfile(String userName) {
Profile profile = new Profile();
School[] school = null;
Experience[] experience = null;

String query = "SELECT ...";
stmt.execute(query);
if(ra.next()){
experience = getExperience(person.getPersonId());
school = getSchool(person.getPersonId());
user.setSchool(school);
user.setExperience(experience);
}
return profile;


I am able to have profile loaded with school[] and experience[] data. I need to get only school[] from profile.

Please advise.

Thanks,
Ananth
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
So according to the following:



there is a method on Profile that returns the schools for a given personId - judging by this code, it looks like you have a reference to person, or something does - I'd find that reference, and then run the code listed above.
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks a lot, got it.
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Yes, I tried but still I am not able to get the schoolname from School.

The following classes are created.

public Profile getProfile(String userName) {
Profile profile = new Profile();
School[] school = null;

String query = "SELECT ...";
stmt.execute(query);
if(rs.next()){
school = getSchool(person.getPersonId());
profile.setSchool(school);
}
return profile;
}

The Profile/School/Person class are

// School.java
package domain;

public class School implements Serializable {

private int schoolId;
private String schoolName;
private int degreeId;
private String degreeName;
private int personId;

//getter / setter methods

public School populate(ResultSet rs) throws Exception {
this.setSchoolId(rs.getInt("schoolid"));
this.setPersonId(rs.getInt("personid"));
this.setSchoolName(rs.getString("schoolname"));
return this;
}
}

// Profile.java
package domain;
public class Profile {

private AccessInfo accessInfo;
private Person person;
private School[] school;
// getter/setter methods.
}

// Person.java
package domain;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.*;
public class Person implements Serializable {
private Integer personId;
private String firstName;
private String lastName;
private String accessInfoId;
private long companyId;
}

Now,

I am trying to retrieve the schoolName from School[]

School[] testSchool = null;

testSchool = dBean.getProfile(personId).getSchool();


I am able to see the data in testSchool, and I want to dynamically populate the schoolname for a personId.

testSchool.length = 2.

Could some one tell me what should be the next step.

Thanks
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Could some one help me on the same.

Thanks in advance.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Retrieving Collection