title: Writing information from SQL database to list
body: <p>I'm working on my homework and I can't complete one piece of my program ... </p>
  
  <p>I have JTable class which makes table in my code ... i have to write method which takes information from sql database and writes it in list </p>
  
  <p>method MUST look like:</p>
  
  <p>public static List selectAnswers (int questionId) throws SQLException, IOException</p>
  
  <p>following code is written by me:</p>
  
  <pre><code>public static List&lt;AnswerRow&gt; selectAnswers (int questionId) throws SQLException, IOException
  {
      Connection veza = connectToDatabase();
  
      Properties query = new Properties();
  
      AnswersTableModel atm = new AnswersTableModel();
  
      String selectAnswers = query.getProperty("selectAnswers");
  
      PreparedStatement preparedStatement = veza.prepareStatement(selectAnswers);
  
      ResultSet rs = preparedStatement.executeQuery();
  
      List&lt;AnswerRow&gt; lista = new ArrayList&lt;AnswerRow&gt;();
  
      while(rs.next()){
  
          String answerText = rs.getString("answerText");
          boolean isRight = rs.getBoolean("answerRight");
  
                      ?????????????????????????????????????????????????
  
  
      }
  
      closeConnectionToDatabase(veza);
  
      return lista;
  }
  </code></pre>
  
  <p>????? field is missing and i dont know what to write there to write information answeText and isRight into AnswerRow class , into AnswerTableModel, into list ... </p>
  
  <p>Code which makes JTable (and is given to me and cannot be changed by my teacher) is here:</p>
  
  <pre><code>package hr.tvz.java.deveti.model;
  
  import java.util.List;
  import java.util.ArrayList;
  
  import javax.swing.table.AbstractTableModel;
  
  public class AnswersTableModel extends AbstractTableModel {
  
      private Object[][] answers;
      private String[] columnNames;
  
      public AnswersTableModel (String[] colNames){
          super();
          columnNames = colNames;
      }
  
      public AnswersTableModel() {
          super();
          this.columnNames = new String[AnswerRow.TABLE_COLUMNS];
          this.columnNames[0] = "Odgovor";
          this.columnNames[1] = "Točan/Netočan";
      }
  
      public java.lang.Class&lt;?&gt; getColumnClass(int columnIndex) {
          return getValueAt(0, columnIndex).getClass();
      }
  
      public int getColumnCount() {
          return AnswerRow.TABLE_COLUMNS;
      }
  
      public int getRowCount() {
          if (answers != null)
              return answers.length;
          else
              return 0;
      }
  
      public Object getValueAt(int row, int column) {
          return answers[row][column];
      }
  
      public String getColumnName(int column){
          return columnNames[column];
      }
  
      public void setValueAt (Object aValue, int rowIndex, int columnIndex){
          answers[rowIndex][columnIndex] = aValue;
      }
  
      public boolean isCellEditable (int rowIndex, int columnIndex){
          return true;
      }
  
      public void addNewRow(){
          Object[] o = new Object[] {"", false};
          if ((answers == null) || (answers.length == 0)) {
              answers = new Object[][] {o};
          }else{
              Object[][] answersTemp = new Object[answers.length + 1][AnswerRow.TABLE_COLUMNS];
              for (int i = 0; i &lt; answers.length; i++)
                  answersTemp[i] = answers[i];
              answersTemp[answersTemp.length - 1] = o;
              answers = answersTemp;
          }
      }
  
      public List&lt;AnswerRow&gt; getAnswerRows() {
          List&lt;AnswerRow&gt; list = new ArrayList&lt;&gt;();
          for (Object[] oRow : answers) {
              AnswerRow row = new AnswerRow();
              row.setAnswer((String) oRow[0]);
              row.setRight((boolean) oRow[1]);
              list.add(row);
          }
  
          return list;
      }
  
      public void setAnswerRows(List&lt;AnswerRow&gt; answerRows){
          if (answerRows.size() == 0 ) {
              this.answers = new Object[0][0];
              return;
          }
          this.answers = new Object[answerRows.size()][AnswerRow.TABLE_COLUMNS];
          for (int i = 0; i &lt; answers.length; i++){
              answers[i][0] = answerRows.get(i).getAnswer();
              answers[i][1] = answerRows.get(i).isRight();
          }
          this.columnNames = new String[AnswerRow.TABLE_COLUMNS];
          this.columnNames[0] = "Odgovor";
          this.columnNames[1] = "Točno/Netočno";
      }
  
      public class AnswerRow {
          public static final int TABLE_COLUMNS = 2;
          private boolean isRight;
          private String answer;
  
          public AnswerRow(){
              answer = "";
              isRight = false;
          }
  
          public AnswerRow(String answer, boolean isRight){
              this.answer = answer;
              this.isRight = isRight;
          }
  
          public String getAnswer() {
              return answer;
          }
  
          public void setAnswer(String answer){
              this.answer = answer;
          }
  
          public boolean isRight(){
              return isRight;
          }
  
          public void setRight(boolean isRight){
              this.isRight = isRight;
          }
      }
  }
  </code></pre>
  
  <p>Please help me .. thanks !</p>