title: How do I display arrayList contents from resultset in Java JDBC?
body: <p>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:</p>
  
  <p><strong>convert the resultset to object model data values</strong></p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p><strong>private method to query the list of questions from the QUESTION table for a survey id</strong></p>
  
  <pre><code>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);
      }
  
  }
  </code></pre>
  
  <p><strong>private method to convert the find the resultset list to an question object and add it to the survey object</strong></p>
  
  <pre><code>private void createQuestionFromResultSet(ResultSet rs, JHAKSurvey survey){
      ArrayList&lt;JHAKQuestion&gt; qList = new ArrayList&lt;JHAKQuestion&gt;();      
      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();
      }
  }
  </code></pre>
  
  <p><strong>private method to convert a resultset to an survey object.</strong></p>
  
  <pre><code>    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;
  }
  </code></pre>
  
  <p>What am I missing? I also seem to get error:</p>
  
  <pre><code>cannot convert from void to JHAKQuestion
  </code></pre>
  
  <p>When I try the method: createQuestionFromResultSet();</p>
  
  <p>Thank You</p>