title: newbie attempt to use Java ArrayList to store ResultSet obtained from database
body: <p>I have a database server communicating with a Java application server using JDBC. I want to store data from the database ResultSet into Java variables. </p>
  
  <p>Here's my Java class, HRPeople:</p>
  
  <pre><code>public class HRPeople {
      public int elements;
      public String[] FirstName;
      public String[] LastName;
      public String[] Email;
      public int[] Salary;
  }
  </code></pre>
  
  <p>I currently use this class to store data from ResultSet, as follows:</p>
  
  <pre><code>query = "SELECT first_name, last_name, email, salary FROM HR.Employees where rownum &lt; 6";
  rset = stmt.executeQuery(query);
  while (rset.next()) {
      returnHRdata.FirstName[ii] = rset.getString("first_name");
      returnHRdata.LastName[ii]  = rset.getString("last_name");
      returnHRdata.Email[ii]     = rset.getString("email");
      returnHRdata.Salary[ii]    = rset.getInt("salary");
      ii = ii + 1;
  }
  </code></pre>
  
  <p>The problem with the above scenario is that the primitive arrays require me to know the number of rows in the ResultSet so that I can properly initialize those arrays. So what I want to do is use an ArrayList instead. How would I modify the above scenario to do this?</p>
  
  <p>Here's my initial attempt (is this close)? Is HRPeople.java file shown above even used in this scenario?</p>
  
  <pre><code>query = "SELECT first_name, last_name, email, salary FROM HR.Employees where rownum &lt; 6";
  rset = stmt.executeQuery(query);
  List&lt;HRPeople&gt; returnHRdata = new ArrayList&lt;HRPeople&gt;();
  while (rset.next()) {
     returnHRdata.FirstName = rset.getString("first_name");
     returnHRdata.LastName  = rset.getString("last_name");
     returnHRdata.Email     = rset.getString("email");
     returnHRdata.Salary    = rset.getInt("salary");
     returnHRdata.add;
  }
  </code></pre>
  
  <p>UPDATE 1:  </p>
  
  <p>If I add to the code the following,</p>
  
  <pre><code>return returnHRdata;
  </code></pre>
  
  <p>I get the following error (any idea why?):</p>
  
  <pre><code>myClass.java:213: incompatible types
  found   : java.util.List&lt;HRPerson&gt;
  required: java.util.ArrayList&lt;HRPerson&gt;
      return returnHRdata;
             ^
  1 error
  </code></pre>