title: How To Display Database Queries Into Table Using Java Servlets And Jsp?
body: <p>I'm very new to web development, so bear with me =)</p>
  
  <p>Ok here is my tech stack I'm working with
  SQL Server 2008 R2,
  Tomcat Server 6.0,
  Java 1.6,
  jQuery,</p>
  
  <p>Here is my problem.</p>
  
  <p>I have a bunch of report type queries I need to run, and I need to display those results as a table on a JSP page for the user to see. The problem I am running into is the method of how to do this.</p>
  
  <p>Most online examples show to store the results of the query in a ResultSet, and putting it into an ArrayList with JavaBeans setters/getters, and then calling that Arraylist in the JSP.</p>
  
  <p>Another problem is, all these queries have different column headers, and these examples do not show how to dynamically create the column headings (most examples are hardcoded).</p>
  
  <p>Here is an example of what I can do so far to generate a report:</p>
  
  <pre><code>    //inside the servlet and sets stuff inside a JavaBean
  public List&lt;ClaimInfoBean&gt; getClaimInfo() throws SQLException {
      List&lt;ClaimInfoBean&gt; claimList = new ArrayList&lt;ClaimInfoBean&gt;();
      while (results.next()) {
          ClaimInfoBean claim = new ClaimInfoBean();
          claim.setClaimNum(results.getString(1));
                      //set more stuff for the bean
          }
  
          claimList.add(claim);
  
      }
  </code></pre>
  
  <p>On the JSP page</p>
  
  <pre><code>        //scriptlet (I know this isnt the best way, but only relevant example I can find)
          List&lt;ClaimInfoBean&gt; claimList = claimData.getClaimInfo();
          Iterator&lt;ClaimInfoBean&gt; claimListIterator = claimList.iterator();
          ClaimInfoBean claim;
          while ( claimListIterator.hasNext() ) {
             claim = ( ClaimInfoBean ) claimListIterator.next();
          //call getXXX to plug into a table
  </code></pre>
  
  <p>For this servlet, all I care about is running x query, to display y table, when a user clicks a link. This servlet should take any query and display any kind of table, so the way I shown above is very restrictive.</p>
  
  <p>Any help in the right direction would be appreciated!</p>