Getting statistics from resultset

Monik Eliz

I have a resultset which returns 5 values. I set that data in a POJO, and added that pojo to a list.

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.]

the top listed data is printed in console, now my question: how can I get the sum of TimeStamp for the Description "Waiting read card". I need to do some statistics, in this case is getting the media value of timeStamp for every Description and I don´t know how to do that. Please, help me!

Sergey Gazaryan

If you want to store that data in database and then retrieve , you need create a database and table (f.e. user) with these columns

name -age -city -car model -house type

Then you can store data ( Insert into user(name, age, city, car_model, house_type) values (?,?,?,?,?) and retrieve (Select * from user where city = 'Madrid') etc.

You could have a POJO entity as mentioned in one comments :

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

  //getters , setters
}

Create corresponding table in database, and manipulate with data with Insert, Select queries.

If you don't want to store data in database, you can create a Maps for easy filtering. 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);
 ...

I hope that will help.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting statistics from resultset

From Dev

Getting Boolean from ResultSet

From Dev

Getting statistics from Coverity

From Dev

Getting resultset from insert statement

From Dev

Getting resultset from insert statement

From Dev

Getting value from previously generated resultset

From Dev

Getting row count from ResultSet in MySQL?

From Dev

Getting the date from a ResultSet for use with java.time classes

From Dev

Unable to fetch the record from sqlite table getting ResultSet Closed error

From Dev

getting ResultSet's values dynamically

From Dev

getting ResultSet's values dynamically

From Dev

Getting the statistics of deterministic variables in PyMC

From Dev

Getting the statistics of deterministic variables in PyMC

From Dev

Getting Wikipedia page view statistics

From Dev

Resultset from trigger MySQL

From Dev

Excluding results from resultset

From Dev

Generate statistics from mysql

From Dev

Getting Jena Resultset after closing query - for modularity

From Dev

Getting Jena Resultset after closing query - for modularity

From Dev

How to get Date from a resultSet

From Dev

Passing ResultSet from Servlet to JSP

From Dev

Get value from ResultSet Java

From Dev

Creating Complex Objects from ResultSet

From Dev

Get URI from resource in ResultSet

From Dev

JDBC Select from Select ResultSet

From Dev

Get Percentage from SubQuery ResultSet

From Dev

pymongo method of getting statistics for collection byte usage?

From Dev

Getting IPv6 TCP statistics

From Dev

Getting sells statistics for given period in PostgreSQL