[Geoserver-users] PostGIS JDBC PreparedStatements and Geometery Types

Hey All,

I’m trying to INSERT a record into my PostGIS table via JDBC in tomcat. Im using the PostGIS JDBC wrapper. This I would think to be very straight forward… so I’ve posted my code to follow.

Connection dbConn = null;
PreparedStatement prep = null;
dbConn = SqlUtils.getConnection("my_postgis_db");
prep = dbConn.prepareStatement("INSERT INTO my_table (my_timestamp,my_string,the_geom) VALUES (?,?,?)");
prep.setTimestamp(1, this.timestamp);
prep.setString(2, "BLAH");
//Now Im trying to set my geometry (Column Name=the_geom)
prep.setString(3, "GeomFromText('POINT(138.59632677 -34.94734398)',4283)");
prep.executeUpdate();

I can’t set the “GeomFromText” as a String [prep.setString()] because, and recieve this error:

org.postgresql.util.PSQLException: ERROR: column "the_geom" is of type geometry but expression is of type character varying
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:308)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
......

Now… I can’t find any supporting documentation for this kind of thing, but I would obviously like to use prepared statements and would think that the prep.setObject() method would allow me to set a org.postgis.Point object in the prepared statement.

Any help is appreciated!!!

-AH

FYI: I find GeoServer on freenode VERY useful!

button.gif

···

Regards,

Andrew Hughes
Software Engineer
LISAsoft Pty. Ltd. (Adelaide)


### LISAsoft Pty. Ltd.
ADELAIDE Office

38 Greenhill Road
Wayville SA 5034
Australia
Telephone +61 8 8272 1555
Facsimile+61 8 8271 1199
SYDNEY Office

Suite 112 The Lower Deck
Jones Bay Wharf
19-21 Pirrama Road
Pyrmont NSW 2009 AUS
Telephone +61 2 8570 5060
Facsimile +61 2 8570 5099
MELBOURNE Office

Level 7 520 Collins Street
Melbourne VIC 3000
Australia
Telephone +61 3 9629 1799
Facsimile +61 3 9629 4955