[postgis-users] How do I handle a ResultSet from a java request?

Nicolas Ribot nicolas.ribot at gmail.com
Tue Oct 6 06:52:28 PDT 2015


Hi Andy,

Your Java ResultSet contains one big row representing your geoJson
document. You can pass it to the client by building a string from the
resultset:
String geojson = resultSet.getString(1);

Be careful to the potential big size of the String: if you expect a big
geojson document from the database, it may be wiser to stream it to the
client from the JDBC connection instead of building a Java String.

Nicolas

On 6 October 2015 at 15:32, Andrew Davis <drsockmonkee at gmail.com> wrote:

> Hi all..
>
> I'm sending my first question out so patience please.
>
> I've got a working servlet on my server that will query for and get
> information back from my postgis DB.
>
> Up until now I have been just parsing the results and sending back a json
> string.  I want to get a GeoJSON back from my db now.
>
> I've been working through the information I found here:
>
> http://www.postgresonline.com/journal/archives/267-Creating-GeoJSON-Feature-Collections-with-JSON-and-PostGIS-functions.html
>
> I can create the table with locations included and a geog value, and I can
> run the query below
>
> SELECT row_to_json(fc)
>  FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features
>  FROM (SELECT 'Feature' As type
>     , ST_AsGeoJSON(lg.geog)::json As geometry
>     , row_to_json((loc_id, loc_name)) As properties
>    FROM locations As lg   ) As f )  As fc;
>
>
> which brings back a single line string and is in the correct format all in PGAdmin3.
>
>
> I have been trying to duplicate this from my server with java and am stuck at the point where I have
>
> run the query and have a 'thing' (ResultSet) but am unsure as to how to handle it and then pass it
>
> back to the client.
>
>
> Any help would be welcome.
>
>
> Andy..
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20151006/c835c999/attachment.html>


More information about the postgis-users mailing list