Inserting an ArrayList of String Arraylists as records into MySQL database
<p>I'm doing a project which will read the contents of every cell of row of an Excel spreadsheet and store all of this information in an ArrayList of String ArrayLists, before inserting all of these rows as records into a MySQL database.</p>

<p>I have a method which extracts this data fine, and returns the full ArrayList of String ArrayLists. The problem I am having is trying to insert these String ArrayLists as records into the SQL database. I'm getting an index out of bounds exception at run time.</p>

<p>Could anyone please try to explain where it is I am going wrong? I think there is some fundemental flaw in my understanding of ArrayLists/looping/JDBC/all of the previous.</p>

<pre><code>public void insertData(ArrayList&lt;ArrayList&lt;String&gt;&gt; l) {
    try {

        String insert = "INSERT INTO 1person (ModuleNumber, ModuleTitle, School, ModuleCoordinator, NumberOfStudents, ExamCW, Courses, Blankety, Blank) VALUES (?,?,?,?,?,?,?,?,?)";
        PreparedStatement ps = con.prepareStatement(insert);

        for (ArrayList&lt;String&gt; ar1 : l) {
            //for(int i = 0; i &lt; ar1.size(); i ++){
            //ps.setString(i+1, ar1.get(i)
            ps.setString(1, ar1.get(0).toString());
            ps.setString(2, ar1.get(1).toString());
            ps.setString(3, ar1.get(2).toString());
            ps.setString(4, ar1.get(3).toString());
            ps.setString(5, ar1.get(4).toString());
            ps.setString(6, ar1.get(5).toString());
            ps.setString(7, ar1.get(6).toString());
            ps.setString(8, ar1.get(7).toString());
            ps.setString(9, ar1.get(8).toString());
            //}

        }
        ps.execute();

    } catch (Exception ex) {
        System.out.println(ex);
    }
}
</code></pre>

<blockquote>
  <p>returns: java.lang.IndexOutOfBoundsException: Index: 8, Size: 8</p>
</blockquote>