Need Help

This is the object I 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;

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 am trying to create a List to populate only the schoolname from testSchool.

for(int i=0; i<testSchool.length; i++){

}

testSchool.length = 2.

What should be the next step. Some one please help.

Thanks,
[800 byte] By [Ananth Ram] at [2007-11-20 11:51:38]
# 1 Re: Need Help
This is the object I createdWhat is the object you created? The Profile?

I am trying to retrieve the schoolName from School[]What does that have to do with the getProfile(..) method you posted?

I am trying to create a List to populate only the schoolname from testSchool.I wish you'd make up your mind what you're trying to do... what is the problem? Creating a List? adding schoolname to it? getting a schoolname out of a School? getting a School out of the School array?

What should be the next step.Well firstly I think you need to explain a bit more clearly exactly what you're trying to do, and what relevance the code you posted has to it, then maybe you can explain which bit you're having trouble with.

Questions are the important thing, answers are less important. Learning to ask a good question is the heart of intelligence. Learning the answer--well, answers are for students. Questions are for thinkers...
R. Schank
dlorde at 2007-11-10 2:14:00 >
# 2 Re: Need Help
Profile is created.

I want to dynamically populate the schoolname for a personId, using the profile object.

Please help me. How do I achieve the same.

Thanks.
Ananth Ram at 2007-11-10 2:14:57 >
# 3 Re: Need Help
I want to dynamically populate the schoolname for a personId, using the profile object.
Please help me. How do I achieve the same.Without knowing what a personId or profile class looks like (the APIs), it's impossible to say. Why don't you post the relevant code?

As a wild guess, I'd say it might be something like:String schoolName = profile.getSchoolName();
personId.setSchoolName(schoolName);However, if it was that obvious, you would have done it already, so like I said, unless you post the relevant code or APIs, I can't help.

That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted...
G. Boole
dlorde at 2007-11-10 2:16:01 >
# 4 Re: Need Help
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.
}

Thanks,
Ananth Ram at 2007-11-10 2:17:01 >
# 5 Re: Need Help
Please use the [CODE]...[/CODE] tags when posting code so it is readable.

You said you wanted to "populate the schoolname for a personId", but a personId is an int, so I can only assume you mean a Person instance that has that personId - but you haven't posted the API for the Person class or the Profile class. Just posting small pieces of code with no explanation of what they are or how the classes work together is pointless.

If you don't know what 'API' means, you should ask, or look it up. JFYI it is an acronym for 'Application Programming Interface'. For a Java class this means all the non-private member declarations.

Incidentally, why does School have a personId member variable?

If you don't want to post the relevant code or APIs, that's fine - but don't expect us to be able to answer your questions, we're not psychic. Equally, if you don't ask a clear, precise question, people are going to find it hard to give you a sensible answer.

You may know what you want to do, but unless you can explain it clearly to someone else, they won't be able to help you.

If you can't explain it simply, you don't understand it well enough...
A. Einstein
dlorde at 2007-11-10 2:18:05 >
# 6 Re: Need Help
I apologize for the same.

I am providing the info what I have. Please find the Person class.

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;
}

Thanks
Ananth Ram at 2007-11-10 2:18:59 >
# 7 Re: Need Help
The Person class you posted has no constructor or methods - it's unusable. I suggest you come back when you have completed it. I can try and help you solve a specific Java problem, but I'm not going to write your classes for you.

The only way to learn a new programming language is by writing programs in it...
B. Kernighan & D. Ritchie
dlorde at 2007-11-10 2:20:05 >
# 8 Re: Need Help
Thanks for the input.

I have created Person.java as below.

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;

public Integer getPersonId() {
return personId;
}
public void setPersonId(Integer personId) {
this.personId = personId;
}

public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}

}

Please advise.

Thanks in advance.
Ananth Ram at 2007-11-10 2:21:06 >
# 9 Re: Need Help
Please advise.That Person class has no schoolname member, so you won't be able to populate it with a schoolname - if that's what you wanted to do... I advise you to figure out what your classes are supposed to do in relation to what your program is trying to achieve, and when you've worked out how they will combine to do this, complete the rest of the code.

From the fragments you've posted so far, none of this is clear to me. If you can't give a clear explanation of your code and what it's supposed to do, or ask a clear question, no-one will be able to help you.

If you get stuck, post a clear question or statement of the problem, together with the relevant, commented code and an explanation of how it relates to the problem. Maybe someone will be able to figure out what you want, probably not me, I'm pretty much out of patience.

Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do...
D. Knuth
dlorde at 2007-11-10 2:22:03 >