[postgis-users] Postgis and JDBC

Norman Barker nbarker at ittvis.com
Wed Jun 6 12:25:08 PDT 2007


Andy,

 

Sorry I had this sitting on my drive I have just updated SVN

 

http://svn.refractions.net/postgis/trunk/java/ejb3/src/org/postgis/hiber
nate/

 

to add the criteria queries, and the dialect

 

so for example using the dialect and hql

 

Query within = entityManager.createQuery("Select
spatial.Within(p.location, person.location) from PersonEntity p,
PersonEntity as person where person = :person");

                            within.setParameter("person", p);

                            ...

within.getResultList();

 

and with criteria queries

 

Criteria criteria =
hManager.getSession().createCriteria(PersonEntity.class);

                            Geometry geom =
PGgeometry.geomFromString("POLYGON(( -180 90, -180 -90, 180 -90, 180 90,
-180 90))");

                            criteria.add(new
WithinExpression("location", geom));

                            List withinResult = criteria.list();

 

Criteria queries are very flexible, suitable for implementing a dynamic
query.

 

I am planning to do another tutorial on this, just trying to fathom out
how to do a map to GML from EJB3 pojos.

 

HTH

 

Norman

 

________________________________

From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Andy
Dale
Sent: 06 June 2007 07:29
To: PostGIS Users Discussion
Subject: [postgis-users] Postgis and JDBC

 

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/4c8f5fbc/attachment.html>


More information about the postgis-users mailing list