Java 从结果集中获取数据太慢

Java 从结果集中获取数据太慢,java,postgresql,jdbc,resultset,Java,Postgresql,Jdbc,Resultset,使用结果集从PostgreSQL数据库获取数据太慢 这是我的密码 for (int i = 0; i < qry_list.size(); i++) { try { resultSet = statement.executeQuery(qry_list.get(i)); resultSet.setFetchSize(0); while (resultSet.next()) { totalfilecrated =

使用结果集从PostgreSQL数据库获取数据太慢

这是我的密码

for (int i = 0; i < qry_list.size(); i++) {
    try {
        resultSet = statement.executeQuery(qry_list.get(i));
        resultSet.setFetchSize(0);
        while (resultSet.next()) {
            totalfilecrated = totalfilecrated
                    + resultSet.getInt(columnname);
        }
    } catch (SQLException e) {

        e.printStackTrace();
    }
}
然后我想得到每个组织单元id的文件数


看到您的第二个查询已经包含了一个对一个列的引用,该列是一个组织单元id,您可能会想直接加入emd组织单元表:

select org.org_unit_id, count(*) as totalfilecreatedelectronic 
  from fl_file ff
  left join vw_employee_details_with_department epd on epd.post_detail_id=ff.file_opened_by_post_fk
  -- join to active entries in emd_org_unit
  inner join from emd.emd_org_unit org ON epd.departmentid=org.org_unit_id  
         AND org.is_active=true
   where ff.file_nature = 'E' 
        and (
  (ff.migration_date>='2011-01-01' and ff.migration_date<='2015-01-01') or 
  (ff.opening_date >='2011-01-01' and ff.opening_date <='2015-01-01')) 
 -- and now group by org_unit_id to get the counts
 group by org_unit_id

如果您为此创建一个SQLFIDLE,我想事情会变得更清楚。

看到您的第二个查询已经包含了对一个列的引用,该列是一个组织单元id,您可能会考虑直接将emd\u组织单元表加入:

select org.org_unit_id, count(*) as totalfilecreatedelectronic 
  from fl_file ff
  left join vw_employee_details_with_department epd on epd.post_detail_id=ff.file_opened_by_post_fk
  -- join to active entries in emd_org_unit
  inner join from emd.emd_org_unit org ON epd.departmentid=org.org_unit_id  
         AND org.is_active=true
   where ff.file_nature = 'E' 
        and (
  (ff.migration_date>='2011-01-01' and ff.migration_date<='2015-01-01') or 
  (ff.opening_date >='2011-01-01' and ff.opening_date <='2015-01-01')) 
 -- and now group by org_unit_id to get the counts
 group by org_unit_id

如果您为此创建一个SQLFIDLE,我想事情会变得更清楚。

那么这些查询是什么?您可以使用一个查询来做正确的事情吗?通常情况下,您应该能够使用join来做这件事。我可以使用java代码吗?我只知道一些sql基础知识。我想选择每个用户id的文件数。我不知道如何使用sql过程。那么,这些查询是什么?您可以使用一个查询来做正确的事情吗?通常情况下,您应该能够使用join来做这件事。我可以使用java代码吗?我只知道一些sql基础知识。我想选择每个用户id的文件数。我不知道如何使用sql过程。
select org.org_unit_id, count(*) as totalfilecreatedelectronic 
  from fl_file ff
  left join vw_employee_details_with_department epd on epd.post_detail_id=ff.file_opened_by_post_fk
  -- join to active entries in emd_org_unit
  inner join from emd.emd_org_unit org ON epd.departmentid=org.org_unit_id  
         AND org.is_active=true
   where ff.file_nature = 'E' 
        and (
  (ff.migration_date>='2011-01-01' and ff.migration_date<='2015-01-01') or 
  (ff.opening_date >='2011-01-01' and ff.opening_date <='2015-01-01')) 
 -- and now group by org_unit_id to get the counts
 group by org_unit_id