title: how to display data from the database into jsp
body: <p>I have some values in list which  I want to compare it with the values stored in database  when I fetch the data from the database during its while loop I use for loop for getting the list values 
  but after that my database data won't show any more if I remove the code of for loop, db data shown where I am doing wrong please help</p>
  
  <pre><code>&lt;%
    try{
        String emi=request.getParameter("emi");
        imei=emi;
        String month=request.getParameter("month");
        String day=request.getParameter("dt");
        String year=request.getParameter("year");
        String month1=request.getParameter("month1");
        String day1=request.getParameter("dt1");
        String year1=request.getParameter("year1");
        String date =month+" "+day+" "+year;
        String date1=month1+" "+day1+" "+year1;
        System.out.println(date);
        System.out.println(date1);
  
        Connection con = history.show.getConnection();
        PreparedStatement ps = con.prepareStatement("select * from sms where  s_imei='"+emi+"' and  sms_date between '"+date+"' and '"+date1+"'");
  
  
        ResultSet rs = ps.executeQuery();
        officialNumber num=new officialNumber();
        ofcNumbers=num.checkNumber();
  
        System.out.println("List size" +ofcNumbers.size());
  
        while(rs.next())
        {
          for(int i=0;i&lt;=ofcNumbers.size();i++)
          {
            String n = ofcNumbers.get(i);
          }                
  %&gt;
  
  &lt;tr&gt;
     &lt;td&gt;                
       &lt;%= rs.getString("sms_phoneNumber")%&gt;
     &lt;td&gt;
       &lt;%= rs.getString("sms_personName")%&gt;
     &lt;td&gt;
       &lt;%= rs.getString("sms_type")%&gt;
     &lt;td&gt;
       &lt;%= rs.getString("sms_date")%&gt;
     &lt;td&gt;
       &lt;%= rs.getString("sms_Time")%&gt;
     &lt;td&gt;
       &lt;%= rs.getString("s_logType")%&gt;
  &lt;/tr&gt;    
  &lt;tr class="alt" &gt;
      &lt;td class="alt" colspan="6" &gt;
        &lt;%= rs.getString("sms_body")%&gt;
        &lt;% 
            }  //end of while        
          } //end of try
          catch(Exception e){}
        %&gt;
  </code></pre>
  
  <p>officialNumber class is just for filling the list with the data</p>
  
  <pre><code>public class officialNumber {
     List&lt;String&gt; ofcNumbers= new ArrayList&lt;String&gt;();
     String listNumber;
    //  Connection con1 = history.show.getConnection();
  
      public List checkNumber()
      {
          Connection con = null;
       PreparedStatement ps = null;
  
       try
       {
        con = getConnection();
        ps = con.prepareStatement("select * from ofcNumbers");
  
        ResultSet rs = ps.executeQuery();
  System.out.println("before while loop") ;
        while ( rs.next())
        {
           System.out.println("after while loop") ;
             listNumber=rs.getString("phone_number");
             ofcNumbers.add(listNumber);
             System.out.println("first list size"+ofcNumbers.size()) ;
  
        }
   rs.close();
   ps.close();
   con.close();
       }
       catch(Exception ex)
       {
           System.out.println( ex.getMessage());
       }
       finally
       {
  
  
         //clean(con,ps);
       }
       return ofcNumbers;
      }
  
  }
  </code></pre>