[postgis-users] JDBC PreparedStatements and inserting geometries...

Markus Schaber schabios at logi-track.com
Sat Feb 26 00:28:35 PST 2005


Hi, Corey,

Corey Puffalt schrieb:

> 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();

Can you try the following instead, using the SQL String concatenation
operator:

INSERT INTO gis_table (id, attr1, geometry, attr2) VALUES (?, ?,
GeometryFromText('MULTILINESTRING (('||?||'))',4267), ?)";

insertStmt.setString(3, geometry);


Markus
-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios at logi-track.com | www.logi-track.com



More information about the postgis-users mailing list