[Gvsig_desarrolladores] group by en GDBMS

fsalas en geocuba.cu fsalas en geocuba.cu
Jue Abr 7 19:09:20 CEST 2011


Dani,
yo estoy empleando esto para conectarme y llenar un combobox revisa a  
ver si modificand puedes emplearlo:

......
	Statement           statement;
     fparametros         param;

     Statement stm = null;
     ResultSet rs;
     Connection conn = null;
      String campo1;
	 String campo2;
	conn = DriverManager.getConnection(param.getDbURL(),  
param.getUsuario().getText(), param.getContrasenna().getText());
	stm = conn.createStatement();
......
   try
     {
stm.execute("select f_table_name as tableName from geometry_columns  
where f_table_schema='"+Esquema+"' group by f_table_name order by  
f_table_name");

****   pudieras poner en tu caso aqui

    String sql = "select " + field_1_Name + ", " + field_2_Name + ",  
count(" +field_2_Name + ") as total from '" + sds.getName() + "' group  
by " +field_1_Name + ", " + field_2_Name + ";";
   stm.execute(sql);

		rs = stm.getResultSet();
		while(rs.next())
		  {
		    campo1 = rs.getString(1);  /***** 1 y 2 son los campos que estas  
consultando en el select si quieres obtener la cantidad debes agregar  
otra con el indice 3
		    campo2 = rs.getString(2);
		}
     } catch (SQLException e) {
  		 e.printStackTrace();
	}

Yo hasta ahora no he empleado SelectionFieldIterator , por eso en  
estos momentos no te puedo comentar sobre el

saludos

Francisco salas





"dani.gonzalez" <dani.gonzalez en geodata.es> escribió:

> Gracias por la respuesta Francisco, he podido avanzar un poquito más :)
>
> ahora me encuentro con otro problema. Si hago la query poniendo los campos
> del group by también en el select:
>
> String sql = "select " + field_1_Name + ", " + field_2_Name + ", count(" +
> field_2_Name + ") as total from '" + sds.getName() + "' group by " +
> field_1_Name + ", " + field_2_Name + ";";
> DataSource ds = sds.getDataSourceFactory().executeSQL(sql,
> DataSourceFactory.MANUAL_OPENING);
>
> ds.getRowCount(); me devuelve 12767 resultados, así que el group by
> funciona.
> pero cuando itero por los resultados:
>
> SelectionFieldIterator iterator = new SelectionFieldIterator(ds, selection,
> 2);
> String  total = "";
> while(iterator.hasNext()) {
>     	 total =
> iterator.next().getStringValue(ValueWriter.internalValueWriter);
> }
>
> al debugar esto, el valor de "total" va siendo 1, 2, 3, 4,..., 12767 (). La
> función "count" no funciona como debería, o estoy iterando mal por los
> resultados de la query?
>
>
> Dani González Moratona
> dani.gonzalez en geodata.es
> ________________________
> Geodata Sistemas, S.L.
> C/Bac de Roda 136 1r 1a
>
> Telf: 93.303.53.67
> http://www.geodata.es
>
>
>
>
>
> --
> View this message in context:  
> http://osgeo-org.1803224.n2.nabble.com/group-by-en-GDBMS-tp6250025p6250645.html
> Sent from the gvSIG desarrolladores mailing list archive at Nabble.com.
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en listserv.gva.es
> http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores
>





Más información sobre la lista de distribución gvSIG_desarrolladores