Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is something you should've found easily when you debug your code...</p> <pre><code>public void createResultList(String query) { ArrayList&lt;ArrayList&lt;String&gt;&gt; data = new ArrayList(); </code></pre> <p>data is an ArrayList of ArrayLists</p> <pre><code> try { ResultSet rs = st.executeQuery(query); </code></pre> <p>A query returning 1 row of 12 columns</p> <pre><code> ResultSetMetaData meta = rs.getMetaData(); for(int i = 0; i &lt; meta.getColumnCount(); i++) { </code></pre> <p>For each column in your recordset, being 12, you add an empty ArrayList in data</p> <pre><code> data.add(i, new ArrayList&lt;String&gt;()); } </code></pre> <p>resulting in data being an ArrayList of 12 empty Arraylists This already explains why data.size() == 12</p> <pre><code> int x = 0; while(rs.next()) { </code></pre> <p>for each record in your recordset, being 1</p> <pre><code> for(int y = 0; y &lt; meta.getColumnCount(); y++) { </code></pre> <p>for each column in your recordset, being 12, you add a string to the ArrayList with the same index as the recordset</p> <pre><code> data.get(x).add(rs.getString(y + 1)); } </code></pre> <p>The first ArrayList in data (data.get(0)) will have 12 Strings All other ArrayLists in data (data.get(x) where x > 0) will remain empty</p> <pre><code> x++; } </code></pre> <p>Resulting in data being an ArrayList of 12 ArrayLists of which only the first ArrayList has 12 Strings and the others are empty</p> <pre><code> } catch(Exception e) { JOptionPane.showMessageDialog(null, e); } ResultTable result = new ResultTable(data); JTable table = new JTable(result); JScrollPane scrollpane = new JScrollPane(table); add(scrollpane); refresh(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload