title: how to get last column value of respective row of excel sheet in java using Apache POI
body: <p>i have following excel sheet </p>
  
  <pre><code>id     JobId     Name      Dept        Add       Salary
  101      41      Bob     Editing    New York     $ 5000 
  </code></pre>
  
  <p>i am passing id,jobid as request parameter to servlet from $.ajax() method. i want to get salary cell data of excel sheet by matching request parameters i.e id and jobid with excel sheet contents and insert it other table. How to do this?</p>
  
  <p>here is my code...</p>
  
  <pre><code>   FileInputStream file = new FileInputStream(fileToBeRead);
     workbook = new HSSFWorkbook(file);
     int jobid = Integer.ParseInt(request.getParameter("jobid"));
  
            if (id == 101) {
               // get first sheet 
                 HSSFSheet sheet = workbook.getSheetAt(0);
                 Iterator&lt;Row&gt; rowIterator = sheet.iterator();
                 statement = conn.createStatement() ;
                 ResultSet resultset = statement.executeQuery("Select job_id,Job,Name, Deptname from Emp,Department where Department.job_id=" + jobid + " AND Emp.Id=" + id + " ");
  
                  while (resultset.next()) { 
  
                     //how to match database result with excel records and save to other table
  
  
  
                  }//resultset.next() ends here...
  
              resultset.close();
          }
  </code></pre>
  
  <p>i try to do like this......? for e.g but it gives error 
  i am trying to match id=101 and Add=New York for e.g and want to get salary data.
  if use <strong>if(data[i][j].equalsIgnoreCase("101"))</strong> condition it works but i want to match both id and Address i.e. <strong>if(data[i][j].equalsIgnoreCase("101") &amp;&amp; data[i][j+5].equalsIgnoreCase("New York"))</strong> it gives error</p>
  
  <pre><code>    int rowNum = sheet.getLastRowNum() + 1;
      int colNum = sheet.getRow(0).getLastCellNum();
      String[][] data = new String[rowNum][colNum];
     // System.out.println("Row No :"+rowNum +" \nCol no:"+colNum);
  
      for (int i = 1; i &lt; rowNum; i++) {
          Row row = sheet.getRow(i);
          for (int j = 0; j &lt; colNum; j++) {
              Cell cell = row.getCell(j);
              String value = null;
              double price;
             // int type = cell.getCellType();
  
              value = cell.getStringCellValue();
  
                      data[i][j] = value;
                      if(data[i][j].equalsIgnoreCase("101") &amp;&amp; data[i][j+4].equalsIgnoreCase("New York"))
                          {
                              Cell lastCellInRow = row.getCell(row.getLastCellNum() - 1);
                              System.out.println(lastCellInRow.getStringCellValue());
  
                      }
  
          }
      }
  </code></pre>