[postgis-users] populatong a postgis via Javaappl.

Obe, Regina robe.dnd at cityofboston.gov
Wed Mar 14 08:19:10 PDT 2007


Forgot to mention - I think you want to do POINT(lon lat)  instead of POINT(lat lon) if you are planning to use a known SRID instead of -1.
 
 
Thanks,
Regina

________________________________

From: Obe, Regina
Sent: Wed 3/14/2007 10:49 AM
To: PostGIS Users Discussion
Subject: RE: [postgis-users] populatong a postgis via Javaappl.



Hi Paul,

Unfortunately I haven't programmed in Java in years.  So hopefully the little bit I do know can help.

1) The postgis driver is included in the postgis package which the latest source you can find here
http://postgis.refractions.net/download/  (postgis-1.2.1.tar.gz)

2) Here is one thread that shows how to do it using the driver
a) http://postgis.refractions.net/pipermail/postgis-users/2005-June/008542.html - if you want to use the driver

I think the driver is mostly used for reading geometries rather than setting them or for setting complex geometries.

b) Using a more elegant variant of what I mentioned.  This one doesn't use the postgis driver but just a plain postgresql driver

http://postgis.refractions.net/pipermail/postgis-users/2006-October/013484.html


So basically your logic in this case would look like

PreparedStatement stmt = con.prepareStatement("insert into ais (mmsi, the_geom) " + "values(?,  GeometryFromText(?,-1))");
stmt.setString(1, "abc");
stmt.setString(2, "POINT(" + lat + " " + lon + ")");
System.out.println(stmt);
stmt.executeUpdate();

Hope that helps,
Regina


________________________________

From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Malm Paul
Sent: Wednesday, March 14, 2007 9:48 AM
To: PostGIS Users Discussion
Subject: [postgis-users] populatong a postgis via Javaappl.



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/a0a246bd/attachment.html>


More information about the postgis-users mailing list