code: public static Integer getIntegerValue(QuerySolution resultRow, String variableName) {
  
          if (resultRow != null) {
              Resource res = resultRow.getResource(variableName);
              if (res != null && res.isLiteral()) {
                  Literal val = res.asLiteral();
                  if (val != null) {
                      return Integer.valueOf(val.getInt());
                  }
              }
          }
  
          return null;
      }
docs: Given a query result from a SPARQL query, obtain the number value at the
  given variable
  
  @param resultRow    the result from a SPARQL query
  @param variableName the name of the variable to obtain
  @return the Integer value, or null otherwise