title: Not writing to new xls sheet using Java
body: <p>I have a java app where it’s writing sql statement output from database to an excel file(xls)
  So when it reaches a the limited number of row that xls has which is around 65000 then it writes to a new sheet.</p>
  <p>This was done previously where it was able to write to second sheet, but when adding the new sheet(sheet4) it’s not working.</p>
  <p>I’m using JXL library and error I’m getting is exceed maximum number of rows, so the two sheets are full but when adding the third it’s not writing to it</p>
  <p>Below is the code.</p>
  <p>rs5 is nothing but an sql statement.</p>
  <pre><code>
  WritableSheet sheet2 = workbook.getSheet(&quot;ServiceSummary&quot;);
                  WritableSheet sheet3 = workbook.getSheet(&quot;ServiceSummary2&quot;);
                  WritableSheet sheet4 = workbook.getSheet(&quot;ServiceSummary3&quot;); // added third sheet to handle more rows
   
                         
                       // Added sheet4 and if else statement to handle max row exception 65000
                          
                          System.out.println(&quot;number of rows in xls&quot; + pos );
                         
                          
                          
                          if (pos &gt; 130000)
                          {
                                System.out.println(&quot;third sheet for ServiceSummary3&quot;);
                                 while(rs5.next()){
                                       sheet4.addCell(new Label(0,1+(counter), customerAccount, arial10format));
                                       sheet4.addCell(new Label(1,1+(counter), rs5.getString(1), arial10format));
                                       sheet4.addCell(new Label(2,1+(counter), rs5.getString(2), arial10format));
                                       sheet4.addCell(new Label(3,1+(counter), rs5.getString(3), arial10format));
                                       sheet4.addCell(new Label(4,1+(counter), rs5.getString(4), arial10format));
                                       sheet4.addCell(new Label(5,1+(counter), rs5.getString(5), arial10format));
                                       sheet4.addCell(new Label(6,1+(counter), rs5.getString(6), arial10format));
                                       sheet4.addCell(new Label(7,1+(counter), rs5.getString(7), arial10format));
                                   try{sheet4.addCell(new Number(8,1+(counter), Double.parseDouble(rs5.getString(8)), arial10format));}catch(Exception e){sheet4.addCell(new Label(8,1+(counter), rs5.getString(8), arial10format));}
                                   try{sheet4.addCell(new Number(9,1+(counter), Double.parseDouble(rs5.getString(9)), arial10format));}catch(Exception e){sheet4.addCell(new Label(9,1+(counter), rs5.getString(9), arial10format));}
                                   try{sheet4.addCell(new Number(10,1+(counter), Double.parseDouble(rs5.getString(10)), arial10format));}catch(Exception e){sheet4.addCell(new Label(10,1+(counter), rs5.getString(10), arial10format));}
                                   counter ++;
                                   pos++;
                               }
                               
                          }
                         
                          else if (pos &gt;= 65000)
                          {
                                 
                                 while(rs5.next()){
                                   sheet3.addCell(new Label(0,1+(counter), customerAccount, arial10format));
                                   sheet3.addCell(new Label(1,1+(counter), rs5.getString(1), arial10format));
                                   sheet3.addCell(new Label(2,1+(counter), rs5.getString(2), arial10format));
                                   sheet3.addCell(new Label(3,1+(counter), rs5.getString(3), arial10format));
                                   sheet3.addCell(new Label(4,1+(counter), rs5.getString(4), arial10format));
                                   sheet3.addCell(new Label(5,1+(counter), rs5.getString(5), arial10format));
                                   sheet3.addCell(new Label(6,1+(counter), rs5.getString(6), arial10format));
                                   sheet3.addCell(new Label(7,1+(counter), rs5.getString(7), arial10format));
                                   try{sheet3.addCell(new Number(8,1+(counter), Double.parseDouble(rs5.getString(8)), arial10format));}catch(Exception e){sheet3.addCell(new Label(8,1+(counter), rs5.getString(8), arial10format));}
                                   try{sheet3.addCell(new Number(9,1+(counter), Double.parseDouble(rs5.getString(9)), arial10format));}catch(Exception e){sheet3.addCell(new Label(9,1+(counter), rs5.getString(9), arial10format));}
                                   try{sheet3.addCell(new Number(10,1+(counter), Double.parseDouble(rs5.getString(10)), arial10format));}catch(Exception e){sheet3.addCell(new Label(10,1+(counter), rs5.getString(10), arial10format));}
                                   counter ++;
                                   pos++;
                               }
                               
                          }
                         
                          else
                           
                          {
                          
                          while(rs5.next()){
                              sheet2.addCell(new Label(0,1+(pos), customerAccount, arial10format));
                              sheet2.addCell(new Label(1,1+(pos), rs5.getString(1), arial10format));
                              sheet2.addCell(new Label(2,1+(pos), rs5.getString(2), arial10format));
                              sheet2.addCell(new Label(3,1+(pos), rs5.getString(3), arial10format));
                              sheet2.addCell(new Label(4,1+(pos), rs5.getString(4), arial10format));
                              sheet2.addCell(new Label(5,1+(pos), rs5.getString(5), arial10format));
                              sheet2.addCell(new Label(6,1+(pos), rs5.getString(6), arial10format));
                              sheet2.addCell(new Label(7,1+(pos), rs5.getString(7), arial10format));
                              try{sheet2.addCell(new Number(8,1+(pos), Double.parseDouble(rs5.getString(8)), arial10format));}catch(Exception e){sheet2.addCell(new Label(8,1+(pos), rs5.getString(8), arial10format));}
                              try{sheet2.addCell(new Number(9,1+(pos), Double.parseDouble(rs5.getString(9)), arial10format));}catch(Exception e){sheet2.addCell(new Label(9,1+(pos), rs5.getString(9), arial10format));}
                              try{sheet2.addCell(new Number(10,1+(pos), Double.parseDouble(rs5.getString(10)), arial10format));}catch(Exception e){sheet2.addCell(new Label(10,1+(pos), rs5.getString(10), arial10format));}
                              pos++;
                          }}
                        
                          rs5.close();
                          rs5 = null;
                      }
                  }
  </code></pre>