title: How to retrieve values after calculation?
body: <p>I have a method to show the values of table that satisfy the condition: show all value in table tblFuel if <code>alarmType != 60</code> and nearest <code>alarmType == 60</code>, all of my code here:</p>
  
  <pre><code>public ArrayList&lt;FuelData&gt; BaoCaoDoXang(String accountID, String deviceID,
          String fromTime, String toTime, String timezone)
          throws DBException, SQLException {
  
      ArrayList&lt;FuelData&gt; list = new ArrayList&lt;FuelData&gt;();
      ResultSet rs = null;
      DBConnection dbc = null;
      Statement stmt = null;
      FuelData reportFuel;
      int alarmType = -1;//(1)initialize here*********************************************************1
      try {
          dbc = DBConnection.getDefaultConnection();
          long epf = ConvertToEpoch(fromTime + " 00:00:00", timezone);
          long epl = ConvertToEpoch(toTime + " 23:59:59", timezone);
          String sql = "SELECT * "
                  + " FROM tblFuel F INNER JOIN tblDoXang DX "
                  + " ON DX.thoiGian = F.timestamp "
                  + " where (F.timestamp BETWEEN " + epf + " and " + epl
                  + ") " + " and F.accountID = '" + accountID
                  + "' and F.deviceID = '" + deviceID
                  + "' and F.alarmType = '" + alarmType//expectation value(4)*************************4
                  + "' order by F.timestamp asc";
  
          stmt = dbc.execute(sql);
          rs = stmt.getResultSet();
          double lastValue = 0;
          int temp = -1;
          while (rs.next()) {
              // double fuel = rs.getDouble("nhienLieu");
              temp = rs.getInt("alarmType");
              if(temp != 60)
                  alarmType = temp;
              if(temp == 60 &amp;&amp; alarmType != -1)//(2)alarmType value after calculation*****************2
              {
              double currentValue = rs.getDouble("fuelLevel");
              double changeValue = lastValue == 0 ? 0 : currentValue
                      - lastValue;
              lastValue = currentValue;
              reportFuel = new FuelData(rs.getString("accountID"),
                      rs.getString("deviceID"), rs.getInt("timestamp"),
                      rs.getDouble("latitude"), rs.getDouble("longitude"),
                      rs.getString("address"), currentValue,
                      rs.getDouble("odometerKM"), rs.getInt("status"),
                      changeValue,alarmType ,//(3)here************************************************3
                      rs.getDouble("nhienLieu"));
              list.add(reportFuel);
              /*
               * if(fuel &gt; 0){ changeValue = fuel; }
               */
              }
          }
  
      } catch (SQLException sqe) {
          throw new DBException("ReportByStatusCode", sqe);
      } finally {
          if (rs != null) {
              try {
                  rs.close();
              } catch (Throwable t) {
              }
          }
          if (stmt != null) {
              try {
                  stmt.close();
              } catch (Throwable t) {
              }
          }
          DBConnection.release(dbc);
      }
      return list;
  }
  </code></pre>
  
  <p>I initialized my variable(alarmType) in (1) <code>int alarmType = -1;//(1)initialize here*********************************************************1</code>
   and then checked the given condition and calculated in (2) and got the satisfied value in (3). I expected to put value of alarmType in (3) </p>
  
  <p><code>double lastValue = 0;
          int temp = -1;
          while (rs.next()) {
              // double fuel = rs.getDouble("nhienLieu");
              temp = rs.getInt("alarmType");
              if(temp != 60)
                  alarmType = temp;
              if(temp == 60 &amp;&amp; alarmType != -1)//(2)alarmType value after calculation*****************2
              {
              double currentValue = rs.getDouble("fuelLevel");
              double changeValue = lastValue == 0 ? 0 : currentValue
                      - lastValue;
              lastValue = currentValue;
              reportFuel = new FuelData(rs.getString("accountID"),
                      rs.getString("deviceID"), rs.getInt("timestamp"),
                      rs.getDouble("latitude"), rs.getDouble("longitude"),
                      rs.getString("address"), currentValue,
                      rs.getDouble("odometerKM"), rs.getInt("status"),
                      changeValue,alarmType ,//(3)here************************************************3
                      rs.getDouble("nhienLieu"));
              list.add(reportFuel);
              /*
               * if(fuel &gt; 0){ changeValue = fuel; }
               */
              }
          }</code></p>
  
  <p>to (4) and then execute the query</p>
  
  <pre><code>String sql = "SELECT * "
                      + " FROM tblFuel F INNER JOIN tblDoXang DX "
                      + " ON DX.thoiGian = F.timestamp "
                      + " where (F.timestamp BETWEEN " + epf + " and " + epl
                      + ") " + " and F.accountID = '" + accountID
                      + "' and F.deviceID = '" + deviceID
                      + "' and F.alarmType = '" + alarmType//expectation value(4)*************************4
                      + "' order by F.timestamp asc";
  </code></pre>
  
  <p>. I have checked and recognized that the value return in (3) is true, however it seemed that the value in (4)(alarmType) which got from (1)(alarmType = -1), but not from (3) so my code return the wrong result. So my question is: how to retrieve correctly value from (3) to put to (4)?(In the other word: how to get value of <code>alarmtype</code> in while loop to put in in SQL query?).(other way) It is very easy if I add one more column in my table to put the values that calculated in (3)(by writing a service in somewhere), but what I can do without of doing that?</p>