title: Appending SQL data into datatables using JAVA in JSP
body: <p>In my SQL Server I have the following result sets after all the condition filtering and sum query execution.</p>
  
  <p><a href="https://i.stack.imgur.com/yAYS9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yAYS9.png" alt="SQL Results"></a></p>
  
  <p>I would like to be shown like this in my page (refer to the screenshot below).</p>
  
  <p><a href="https://i.stack.imgur.com/uKhrI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uKhrI.png" alt="![Actual Results Needed"></a></p>
  
  <p>I have tried the below JAVA code that gave me the results that I appended into my datatables.</p>
  
  <pre><code>&lt;%
  ArrayList&lt;String[]&gt; rows = sqlq.querySQL();
  String rowsetdate = new String();
  String rowres1 = new String();
      for(String[] rowset : rows) { 
        rowsetdate = rowset[0];
        rowres1 = rowres1 + rowset[1]+ ",";
          for(String rowres2 : rowset) {
          rowres1 = rowres1 + rowres2 + ",";
           }
        rowres1 = rowres1.substring(0, rowres1.length()-1);
        rowres1 = rowres1 + "|";
       }
  rowres1 = rowres1.substring(0, rowres1.length()-1);
  %&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;%if (rowres1  == null) out.print(""); else out.print(rowres1);%&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p><code>sqlq.querySQL()</code> is used to send my SQL query to JDBC in order for me to send query to my DB.</p>
  
  <p>Photo below is the appended data in my datatables after the code execution, on the left is the Date and on the right is the data.</p>
  
  <p><a href="https://i.stack.imgur.com/x9GgY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x9GgY.png" alt="Sets of Data"></a></p>
  
  <p>I tried some different code,</p>
  
  <pre><code>&lt;%
  ArrayList&lt;String[]&gt; rows = sqlq.querySQL();
   for(String[] rowset : rows) {
  &lt;tr&gt;
  &lt;td&gt;&lt;%if (rowset[0]  == null) out.print(""); else out.print(rowset[0]);%&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%if (rowset[1]  == null) out.print(""); else out.print(rowset[1]);%&gt;&lt;/td&gt;
  &lt;/tr&gt;
  }
  %&gt;
  </code></pre>
  
  <p>which did not achieve my expected results also, it returns the data like how I see it in my SSMS (check screenshot below)</p>
  
  <p><a href="https://i.stack.imgur.com/Lc8Ca.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lc8Ca.png" alt="wrong sql"></a></p>
  
  <p>What did I do wrong and how should I do it to get my expected outcome? (screenshot below) </p>
  
  <p><a href="https://i.stack.imgur.com/8sSkp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8sSkp.png" alt="expected outcome"></a></p>
  
  <p>Appreciate the help from all of you. </p>