Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:50:10+00:00 2026-06-12T02:50:10+00:00

I using MVC for developing a web project in Java. My problem is that

  • 0

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

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:50:11+00:00Added an answer on June 12, 2026 at 2:50 am

    If the different beans all contain a certain method (or methods), you can create an interface and make each bean implement it.

    Here’s a similar question that just got asked:

    Treating different objects the same

    Silly example code:

    interface CommentItem {
        public String getComment();
    }
    
    
    class ModeratorComment implements CommentItem {
        public String getComment() {
            return "Comment from moderator";
        }
        // other moderator-specific code...
    }
    
    
    
    class StudentComment implements CommentItem {
        public String getComment() {
            return "Comment from student";
        }
        // other student-specific code...
    }
    
    
    class CommentContainer {
    
        private List<CommentItem> commentList;
    
        public List<CommentItem> getCommentList() {
            return commentList;
        }
    
        public void addComment(CommentItem someComment) {
            commentList.add(someComment);
        }
    }
    
    
    class TestIt() {
    
        public static void main(String[] args) {
    
            StudentComment sc = new StudentComment();
            ModeratorComment mc = new ModeratorComment();
    
            CommentContainer comments = CommentContainerFactory.createCommentContainer();
            comments.add(sc);
            comments.add(mc);
    
            for (CommentItem ci : comments.getCommentList()) {
                System.out.println(ci.getComment());
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a website using MVC 3, I have a web setup project
I'm developing a Web Site using ASP.NET MVC 3, Nowadays I need to encrypt
I'm developing an web application using asp.net mvc, and i need to do a
I am using ASP.NET MVC for developing a web site. I am using jquery
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the
I am developing an MVC application using nHibernate; running through VS's built in web
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1 and
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1, however,
I'm developing an website using asp.net mvc with MySQL and I need to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.