title: Implement pagination using offset in java jdbc
body: <p>I am trying to implement pagination using java jdbc. My query takes the limit which is the batch size and offset.</p>
  
  <p>How do i increment the offset after completion of each batch. I am unable to understand how can i use this offset to achieve the functionality. I tried to write a wrapper method which recursively calls the method which takes the offset.</p>
  
  <p>Here is my query </p>
  
  <pre><code>select
  ECId,InvId,ApplianceId,ProgName,CollectStartTS,CollectEndTS,CRPartyId,
  HostName,IPAddess,SoftwareVer,OsType,collectserialnum,
  CollectProductId,SNMPLoc,HWAlertCnt,SWAlertCnt,UploadProcEndTS
  from inventory_details
  </code></pre>
  
  <p>and the code</p>
  
  <pre><code>public void getInventory() throws SQLException {
      int batch = Integer.parseInt(PropertyFileReader.getInstance()
           .getProperty("BATCHSIZE"));
      int offset= 0;
      while(offset&lt;batch){
          DrillDAO dao = new DrillDAO();
          dao.getAllInventoryDetails(offset); 
      }   
      offset = offset+batch+1;
  }
  
  public ArrayList&lt;InventoryDetail&gt; getAllInventoryDetails(int offset)
               throws SQLException {              
      int batchSize = Integer.parseInt(PropertyFileReader.getInstance()
                      .getProperty("BATCHSIZE"));             
  
      ArrayList&lt;InventoryDetail&gt; inventoryDetailList = new ArrayList&lt;InventoryDetail&gt;();              
  
      Connection connection = null;
      Statement statement = null;
      ResultSet resultset = null;
      try {
          Class.forName(getJdbcDriver());
          connection = DriverManager.getConnection(
                       getJdbcURL(), getUserName(), getPassword());
          statement = connection.createStatement();
          LOGGER.info("Start time    " + CPUUtils.getCpuTime());
          resultset = statement.executeQuery(getQuery() 
                    + " " + "LIMIT" + " " + batchSize + " " 
                    + "OFFSET" + " " + offset);
          LOGGER.info("End time    " + CPUUtils.getCpuTime());
  
          while (resultset.next()) {
              InventoryDetail id = new InventoryDetail();
              id.setEcId(resultset.getString(1));
              id.setInvId(resultset.getString(2));
              id.setApplianceId(resultset.getString(3));
              id.setProgName(resultset.getString(4));
              id.setCollectStartTS(resultset.getString(5));
              id.setCollectEndTS(resultset.getString(6));
              id.setCrPartyId(resultset.getString(7));
              id.setHostName(resultset.getString(8));
              id.setIpAddess(resultset.getString(9));
              id.setSoftwareVer(resultset.getString(10));
              id.setOsType(resultset.getString(11));
              id.setCollectSerialNum(resultset.getString(12));
              id.setCollectProductId(resultset.getString(13));
              id.setSnmpLoc(resultset.getString(14));
              id.setHwAlertCnt(resultset.getString(15));
              id.setSwAlertCnt(resultset.getString(16));
              id.setUploadProcEndTS(resultset.getString(17));
              inventoryDetailList.add(id);
          }
      } catch (SQLException se) {
          se.printStackTrace();
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
          try {
              if (statement != null)
                  statement.close();
          } catch (SQLException se2) {
          }
          try {
              if (connection != null)
                  connection.close();
          } catch (SQLException se) {
             se.printStackTrace();
          }
      }  
      return inventoryDetailList;
  }
  </code></pre>