[postgis-users] Inserting geometries using a JDBC PreparedStatement

Corey Puffalt cplists at gmail.com
Mon Jul 24 10:22:06 PDT 2006


All...

Has anyone been able to insert geometries using a standard JDBC
PreparedStatement successfully with Postgis 1.1.3 & Postgresql 8.1.4?  I had
this working with postgis 0.8 & Postgresql 7.4.1 but I'm now upgrading to
the latest versions.

Here's what I'm attempting to do (stripped down for simplicity...error
handling removed etc.):

==========>8==========
String psqlInsertLine =
   "INSERT INTO gis_table (id, attr1, geometry, attr2) " +
   "VALUES (?, ?, GeometryFromText(?,4267), ?)";
PreparedStatement insertStmt = conn.prepareStatement(psqlInsertLine);

String geometry = getGeometry(attr1, attr2); // get a geometry based
on the attributes...

insertStmt.setString(1, id);
insertStmt.setString(2, attr1);
insertStmt.setString(3, geometry);
insertStmt.setString(4, attr2);

insertStmt.executeUpdate();

==========8<==========

geometry is a string. For example:
"'LINESTRING(-113.7568111 57.1167611 ,-113.7568111 57.1167611 ,-113.8803611
57.1146194 ,-113.8803611 57.1146194 )'"

This works under 0.8 but with 1.1.3 I'm getting the following error:

org.postgresql.util.PSQLException: ERROR: Invalid OGC WKT (does not start
with P,L,M or G)

As you can see my WKT does, in fact, start with an L ?!?

Does anyone how to get this working?  What am I doing wrong?

Thanks,
Corey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060724/db3bdc5a/attachment.html>


More information about the postgis-users mailing list