I using MVC for developing a web project in Java.
My problem is that i need to return three different beans from a class. All three beans have multiple objects so I am right now adding each same bean object in a list and returning three different lists.
Okay to make it more clear I need to retrieve all contents from a table that stores comments. So all comment text are stored in one bean called comment and added in a list called listcomment. The name of member who made the comment are added in another bean called member and again those are added in list called listmember.
So is there any possible way so that both these beans can be added in a same list?
public class TeleCommentView {
int qid;
TeleComment comment;
TeleHospital hospital;
doctorperson doctor;
ConnectionFile connection = new ConnectionFile();
List<TeleComment> listcomment = new ArrayList<TeleComment>();
List<doctorperson> listdoctor = new ArrayList<doctorperson>();
List<TeleHospital> listhospital = new ArrayList<TeleHospital>();
public TeleCommentView(int qid)
{
this.qid = qid;
process();
}
public void process()
{
int count=0;
try
{
Connection con = connection.connectionfile();
PreparedStatement pstmt = con.prepareStatement("select TeleHospital.HospitalName,DoctorDetail.Name,TeleComment.Comment,TeleComment.SDate from"
+ "( (TeleComment left join TeleHospital on TeleHospital.HospitalId=TeleComment.Hid) "
+ "left join DoctorDetail on DoctorDetail.DoctorId = TeleComment.Did) "
+ "where TeleComment.Qid=?");
ResultSet rs = pstmt.executeQuery();
while(rs.next())
{
comment = new TeleComment();
comment.setComment(rs.getString("Comment"));
comment.setSdate(rs.getDate("SDate"));
listcomment.add(count,comment) ;
/******End of comment**************/
//Add doctor or hospital name as required
doctor = new doctorperson();
hospital = new TeleHospital();
if(rs.getString("HospitalName").equals(null))
{
doctor.setName(rs.getString("Name"));
listdoctor.add(count,doctor);
}
else
{
hospital.setHospitalname(rs.getString("HospitalName"));
listhospital.add(count,hospital);
}
count++;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public List getCommentList()
{
return listcomment;
}
public List getDoctorList()
{
return listdoctor;
}
public List getHospitalList()
{
return listhospital;
}
}