1

我想做这个查询:

Select
    srid,
    substring(srtext
              from (position('DATUM["' in srtext)+7)
              for (position('ID["' in srtext)+2)
                - (position('DATUM["' in srtext)+7))
  from spatial_ref_sys
  order by substring

所以,我创建了一个

Query query = em().createNativeQuery(QUERY)

还要创建一个具有 Long srid 和 String sridText 的 Srid 对象。

我需要获取这些值并将其放入列表中。sridText 上的子字符串,显然是 srid 变成了 Long srid。

请帮忙!!!

4

1 回答 1

1

找到了答案。首先,我做了一个名为 getSrid 的 plpgsql 函数

CREATE OR REPLACE FUNCTION getSRID() returns text[] as $$
declare
 resultado text[];
 consulta cursor for
 Select srid,substring(srtext from (position('DATUM["' in srtext)+7) 
 for(position('ID["' in srtext)+2)
  - (position('DATUM["' in srtext)+7)) as sub
 from spatial_ref_sys;
 cont int;
 i int;
 sridd int;
 srTextt text;
begin
 open consulta;
 i=1;
 EXECUTE 'SELECT COUNT(*) FROM SPATIAL_REF_SYS' into cont;
 resultado := ARRAY[cont];
 while(i<cont) loop
  fetch consulta into sridd,srTextt;
  resultado[i] := sridd;
  resultado[i+1] := srTextt;
  i:=i+2;
 end loop;
 return resultado;
end
$$ language plpgsql; 

如您所见,我在返回时得到了一个 Text[],所以在我的 java 调用中,我将对象转换为 String[]:

public List<SridDTO> listaa(){
    int i = 0;
    List<SridDTO> list = new ArrayList<SridDTO>();
    Query query = em().createNativeQuery("Select getSrid()");
    String[] vector = (String[]) query.getSingleResult();
    while(i<vector.length){
        SridDTO sridDTO = new SridDTO(new Long(vector[i]),vector[i+1]);
        i = i + 2;
        list.add(sridDTO);
    }
    return list;
}
于 2012-08-02T18:29:24.503 回答