[postgis-users] Postgis and JDBC

Andy Dale andy.dale at gmail.com
Wed Jun 6 06:29:25 PDT 2007


Hi,

I am using Postgis via JDBC (namely spatial
EJB).  I just have a quick question about setting geometry parameters
in a JDBC query,
the question is it possible just to set a java object in the query or
does it always parse (binaryParser,
binarayWriter) the string representation of the object.

A small example is the following query:

// Create a new Polygon
Polygon p = new Polygon("((0 0, 0 10, 10 10, 10 0, 0 0))");

String query = "SELECT * FROM thetable WHERE
                          the_geom && ?
                          AND Intersects(the_geom, ?)";


PreparedStatement prep = mDBConnection.prepareStatement(query);

// not sure what type to set, set blob ????
prep.setBlob(1, p);
prep.setBlob(2, p);

prep.execute();

// DO STUFF WITH RESULT

I only ask this question because when using Postgis with EJB3 i cannot just
set the object as a parameter as it needs to be contained in single
quotation marks, if not the geometry is invalid (parse error - invalid
geometry)

Any suggestions ?

Thanks,

Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070606/e1d13b9b/attachment.html>


More information about the postgis-users mailing list