从结果集中获取统计信息

Getting statistics from resultset

我有一个包含 returns 5 个值的结果集。我将该数据设置在 POJO 中,并将该 pojo 添加到列表中。

datapojo = new OutputViewDataPOJO();
datapojo.setTime(resultado.getInt(1));
datapojo.setCommandDesc(resultado.getString(2));
datapojo.setOkError(resultado.getString(3));
datapojo.setResultDesc(resultado.getString(4));
datapojo.setResultCode(resultado.getInt(5));                    
listPojo.add(datapojo);

    [Description:Call connect, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting open complete, TimeStamp:2468, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Reading card, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting read card, TimeStamp:10329, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Reading card, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting read card, TimeStamp:6671, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Reading card, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting read card, TimeStamp:6704, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Reading card, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting read card, TimeStamp:6578, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Reading card, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting read card, TimeStamp:6578, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Reading card, TimeStamp:0, OkError:OK, ResultCode:0, ResultDesc:null.]
    [Description:Waiting read card, TimeStamp:6594, OkError:OK, ResultCode:0, ResultDesc:null.]

列在最前面的数据打印在控制台中,现在我的问题是: 如何获得描述 "Waiting read card" 的时间戳总和。我需要做一些统计,在这种情况下是获取每个描述的 timeStamp 的媒体值,我不知道该怎么做。 请帮帮我!

如果您想将该数据存储在数据库中然后检索,您需要使用这些列创建 databasetable (f.e. user)

name -age -city -car model -house type

然后就可以存储数据了( Insert into user(name, age, city, car_model, house_type) values (?,?,?,?,?) 并检索 (Select * from user where city = 'Madrid') 等

您可以拥有一个评论中提到的 POJO 实体:

public class User
{
   private int id;
   private String name;
   private int age;
   private String city;
   private String carModel;
   private String houseType;

  //getters , setters
}

在数据库中创建相应的 table,并使用 InsertSelect 查询处理数据。

如果您不想将数据存储在数据库中,您可以创建一个 Maps 以便于过滤。 f.e.

 User user = ...; //an instance of User
 Map<String, List<User>> userCityMap = new HashMap<String,List<User>>(); 
 List<User> userWithThatCity = map.get(user.getCity());
 if(userWithThatCity == null)
 {
   userWithThatCity = new ArrayList<User>();
   userCityMap.put(user.getCity(), userWithThatCity);
 }
 userWithThatCity.add(user);
 ...

希望对您有所帮助。