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 8270833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:41:54+00:00 2026-06-08T06:41:54+00:00

So I am making a simple java project to play around with JDBC in

  • 0

So I am making a simple java project to play around with JDBC in glassfish and see how it works. The program just shows you a list of surveys and a list of questions for the survey you select. However i cant seem to display the list of questions for the survey I selected. I keep getting empty values. These are the methods I have created:

convert the resultset to object model data values

public JHAKSurvey findSurvey(long id) {
    System.out.println("JDBC: FIND SURVEY");
    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    JHAKSurvey survey = null;
    try {
        connection = openConnection();
        String query = "SELECT * FROM APP.SURVEY WHERE ID=?";
        ps = connection.prepareStatement(query);
        ps.setLong(1, id);
        rs = ps.executeQuery();
        while (rs.next()) {
            survey = createSurveyFromResultSet(rs);             
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        closeConnection(connection);
    }
    return survey;
}

private method to query the list of questions from the QUESTION table for a survey id

private void findQuestionsBySurvey(JHAKSurvey survey){
    System.out.println("JDBC: FIND QUESTIONS BY SURVEY");
    Connection connection = null;
    PreparedStatement ps = null;

    try {
        connection = openConnection();
        String query = "SELECT * FROM APP.QUESTION WHERE SURVEYID=?";
        ps = connection.prepareStatement(query);
        ps.setLong(1, survey.getId());
        ps.executeQuery(query);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        closeConnection(connection);
    }

}

private method to convert the find the resultset list to an question object and add it to the survey object

private void createQuestionFromResultSet(ResultSet rs, JHAKSurvey survey){
    ArrayList<JHAKQuestion> qList = new ArrayList<JHAKQuestion>();      
    JHAKQuestion question = new JHAKQuestion();
    JHAKSurvey ss = new JHAKSurvey();
    //qList.add(survey.getQuestions());

    try {
        while (rs.next()) {
            //question.setDescription(qList.toString());
            question.setId(rs.getLong("ID"));
            question.setDescription(rs.getString("DESCRIPTION"));
            qList.add(question);
            survey.setQuestions(qList);
        }               
        System.out.println("createQuestionFromResultSet : JDBC : successful");
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        System.out.println("createQuestionFromResultSet : JDBC : fail");
        e.printStackTrace();
    }
}

private method to convert a resultset to an survey object.

    private JHAKSurvey createSurveyFromResultSet(ResultSet rs){
    JHAKSurvey survey = new JHAKSurvey();
    Boolean active = false;
    String yes;
    try {
        yes = rs.getString("ACTIVE");
        survey.setId(rs.getLong("ID"));
        survey.setTitle(rs.getString("TITLE"));
        if (yes.equals(Character.toString('Y'))) {
            survey.setActive(true);
        } else {
            survey.setActive(false);
        }   
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    return survey;
}

What am I missing? I also seem to get error:

cannot convert from void to JHAKQuestion

When I try the method: createQuestionFromResultSet();

Thank You

  • 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-08T06:41:55+00:00Added an answer on June 8, 2026 at 6:41 am

    Look at your method:

    private void findQuestionsBySurvey(JHAKSurvey survey){
    

    You want to get the questions of a survey, but the method returns void. Make it return a List<Question>. And in the body of the method, iterate through the resultset, transform each row into a question, add the question to a List<Question>, and return this list.

    Or, if the goal of the method is to add questions to the survey passed as argument, then rename the method to

    private void addQuestionsToSurvey(JHAKSurvey survey) {
    

    and, inside the method body, call the method createQuestionFromResultSet (which should be named createQuestionsFromResultSetAndAddThemToSurvey), with the resultset and the survey as argument:

    private void findQuestionsBySurvey(JHAKSurvey survey){
        System.out.println("JDBC: FIND QUESTIONS BY SURVEY");
        Connection connection = null;
        PreparedStatement ps = null;
    
        try {
            connection = openConnection();
            String query = "SELECT * FROM APP.QUESTION WHERE SURVEYID=?";
            ps = connection.prepareStatement(query);
            ps.setLong(1, survey.getId());
            ResultSet rs = ps.executeQuery(query);
            createQuestionFromResultSet(survey); 
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeConnection(connection);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple program in Java. Given a set of letters it'll list
I'm making a simple drawing app on Android. I'm using the FingerPaint.java provided with
I am also new to Java and Android Development, been making a simple game
I'm making a very simple 2D RPG in Java. My goal is to do
Let's say I'm making a fairly simple web application using JAVA EE specs (I've
I am currently making a simple calculator parser in Java, to deal only with
I am making a simple 2D game in java... I am using java's Graphics2D
I am making a simple Java Swing GUI chessboard where the player can drag
I'm making a simple Kakuro application in Java Swing and I have used JButton
I am making a Tic Tac Toe Program in java because i am learning

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.