[postgis-users] JDBC PreparedStatements and inserting geometries...
Corey Puffalt
cplists at gmail.com
Fri Feb 25 13:33:43 PST 2005
All,
I'm having problems performing inserts of geometry in Java using a
PreparedStatement. 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('MULTILINESTRING ((?))',4267), ?)";
PreparedStatement insertStmt = null;
String geometry = getGeometry(attr1, attr2); // get a geometry based
on the attributes...
insertStmt.setObject(1, id);
insertStmt.setObject(2, attr1);
insertStmt.setObject(3, geometry);
insertStmt.setObject(4, attr2);
insertStmt.executeUpdate();
==========8<==========
geometry is a string like so: "-114.3252583 57.0771 ,-114.3227833
57.0313528 ,-114.3285083 56.9643194" for example.
The particular example above results in a:
org.postgresql.util.PSQLException: The column index is out of range:
4, number of columns: 3.
The error occurs presumably because of the single quotes. How can I
get around this? I've tried parameterizing everything between the
single quotes but that doesn't work either...instead I get:
java.sql.SQLException: ERROR: function geometryfromtext(character
varying, integer) does not exist
Is there anyway to use a PreparedStatement with geometries?
Thanks,
Corey
PS: Is there a searchable archive of the mailing list somewhere?
More information about the postgis-users
mailing list