title: returning an arraylist of arraylist from a resultset in java
body: <p>I created a database wrapper class in java and created a method called <code>fetchAll(query)</code>.</p>
  
  <pre><code>this.openConnection();
  
  ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();
  PreparedStatement stmt = this.conn.prepareStatement(query);
  ResultSet resultset = stmt.executeQuery();
  
  ResultSetMetaData metadata = resultset.getMetaData();
  int numcols = metadata.getColumnCount();
  
  while (resultset.next()) {
      int i = 1;
      while (i &lt; numcols) {
          results.add(resultset.getString(i++));
      }
  }
  
  this.closeConnection();
  
  return results;
  </code></pre>
  
  <p>Now it returns something like this:</p>
  
  <pre><code>[1, name1, address1, age1, 2, name2, address2, age2, 2, name2, address2, age3]
  </code></pre>
  
  <p>Which I found odd and the method does not return all columns, it lacks 1 column, why is it?</p>
  
  <p>How can I achieve something like this</p>
  
  <pre><code>[
    [1,name1,address1,age1,bday1],
    [2,name2,address2,age2,bday2],
    [3,name3,address3,age3,bday3]
  ]
  </code></pre>