[postgis-users] Inserting geometries using a JDBC PreparedStatement

Guido Lemoine guido.lemoine at jrc.it
Tue Jul 25 00:28:31 PDT 2006


Corey,

Apparently, you do no longer need the single quote around the LINESTRING.
I reproduced your problem and found that dropping the single quotes 
solves the
problem. I am using 8.0.3/1.0. Curious.

GL

Corey Puffalt wrote:

> 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
>
>------------------------------------------------------------------------
>
>_______________________________________________
>postgis-users mailing list
>postgis-users at postgis.refractions.net
>http://postgis.refractions.net/mailman/listinfo/postgis-users
>  
>



More information about the postgis-users mailing list