[postgis-users] populatong a postgis via Javaappl.

Malm Paul paul.malm at saabgroup.com
Wed Mar 14 06:48:24 PDT 2007


I would like to insert a point in a postgis database.

BEGIN;
INSERT INTO "public"."ais" ("mmsi", the_geom) 
VALUES ('123', ,GeometryFromText('POINT(-73.910977172366
40.729270630126)',-1));
END;

This is what I have tried in java.

static private Connection con = null;
double lat 63.049813568477724;
double lon 20.26472335111486;

Class.forName(org.postgresql.Driver);
con = DriverManager.getConnection("jdbc:postgresql:postgis", "username",
"pw");
PreparedStatement stmt = con.prepareStatement("insert into ais (mmsi,
the_geom) " + "values(?,  ?)");
stmt.setString(1, "abc");
stmt.setString(2, "GeometryFromText('POINT(" + lat + " " + lon +
")',-1)");
System.out.println(stmt);
stmt.executeUpdate();

This is what System.out.println prints:
insert into ais (mmsi,  the_geom) values(abc,
GeometryFromText('POINT(63.049813568477724 20.26472335111486)',-1))

This is the Error message
org.postgresql.util.PSQLException: ERROR: column "the_geom" is of type
geometry but expression is of type character varying

 

Could someone please tell me where I can read about how to do this, or
if someone could send me a little example? I have not found any
documentation that shows this (at least as far as I understand I'm new
at both Java and SQL).

This must be a basic thing, but I don't get it...

Thanks..

 

________________________________



The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended solely for the
addressee. If you received this in error, please contact the sender
and delete the material from any computer.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070314/969a9599/attachment.html>


More information about the postgis-users mailing list