[postgis-users] postgis with jdbc

Markus Schaber schabi at logix-tt.com
Tue Jan 10 07:16:46 PST 2006


Hi, Gilbert,

Sorry for the late answer, I'd been on holidays lately.

Gilbert, Antoine wrote:

> The jdbc example provided by the documentation dosen’t work for me.
> Given these 2 statements :
> 
> ((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
> ((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");

It seems that this is the Code for the pgjdbc 7.2 driver, it should be
PGConnection now.

Did you have a look at the example code delivered with the postgis source?

> ((PGConnection)connection).addDataType("geometry",”org.postgis.PGgeometry”);
>         ((PGConnection)connection).addDataType("box3d",”
> org.postgis.PGgeometry”);

Ouch, your second command should be changed to use the PGbox3d instead
PGgeometry.

Also, did you notice that there are two other ways to initialize the
PostGIS driver extension, via automatic configuration (simply drop the
postgis jar into the same classpath location as the pgjdbc jar if you
use 8.0 or newer pgjdbc drivers), and via the DriverWrapper classes?

>         Statement stmt = connection.createStatement();
> 
>         ResultSet rs = stmt.executeQuery("select \"STREET\",
> AsText(\"geom\") as geom from rue_test");

You select asText(geom) converts the geometry to a varchar which is then
returned to the client. The pgjdbc driver maps varchar to a string.

Try the following:

|         ResultSet rs = stmt.executeQuery("select \"STREET\",
| \"geom\" as geom from rue_test");

This way, the server should tag the result as type "geometry" and not
"varchar".


HTH,
Schabi

-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org



More information about the postgis-users mailing list