Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#609 closed defect (fixed)

Bad source code in manual section 5.2 Java Clients

Reported by: simoc Owned by: pramsey
Priority: low Milestone: PostGIS 1.5.3
Component: postgis Version: 1.5.X
Keywords: history JDBC client documentation Cc:

Description

I found some errors in the example Java source code in section 5.2 'Java Clients (JDBC)' of postgis-1.5.1.pdf:

Replace:

((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");

with:

((org.postgresql.jdbc3.Jdbc3Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.jdbc3.Jdbc3Connection)conn).addDataType("box3d","org.postgis.PGbox3d");

Replace:

ResultSet r = s.executeQuery("select ST_AsText(geom) as geom,id from geomtable"); 

with:

ResultSet r = s.executeQuery("select geom,id from geomtable");

Replace:

if( geom.getType() = Geometry.POLYGON ) { 

with:

if( geom.getGeoType() == Geometry.POLYGON ) {

Change History (4)

comment:1 Changed 8 years ago by simoc

Documentation source file to be updated is doc/using_postgis_app.xml

comment:2 Changed 8 years ago by robe

Resolution: fixed
Status: newclosed

Okay I feel the recommendation for first part is wrong. Last bit of java programming I tortured myself with -- I think I used this syntax -- http://jdbc.postgresql.org/documentation/publicapi/org/postgresql/PGConnection.html and a JDBC4 driver.

So I have instead opted to replace the first part with

    ((org.postgresql.PGConnection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.PGConnection)conn).addDataType("box3d","org.postgis.PGbox3d");

the rest of the suggestions look fine, but I haven't tested the code and am not really setup to at the moment.

so fixed at r7362 for PostGIS 1.5 and r7363 for PostGIS 2.0

comment:3 Changed 8 years ago by simoc

Yes, using PGConnection.addDataType(String, String) also works for me, although that method is deprecated. The recommended replacement method in the PGConnection Javadoc is:

((org.postgresql.PGConnection)conn).addDataType("geometry",Class.forName("org.postgis.PGgeometry"));
((org.postgresql.PGConnection)conn).addDataType("box3d",Class.forName("org.postgis.PGbox3d"));

That method also works correctly for me.

comment:4 Changed 8 years ago by robe

Keywords: history added

Done r7383 for PostGIS 1.5, r7384 PostGIS 2.0

Simoc, What is your real name?

Thanks, Regina

Note: See TracTickets for help on using tickets.