<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>RE: [postgis-users] populatong a postgis via Javaappl.</TITLE>
</HEAD>
<BODY>
<DIV id=idOWAReplyText42195 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>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.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Thanks,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>Regina</FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Obe, Regina<BR><B>Sent:</B> Wed 3/14/2007
10:49 AM<BR><B>To:</B> PostGIS Users Discussion<BR><B>Subject:</B> RE:
[postgis-users] populatong a postgis via Javaappl.<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Hi Paul,<BR><BR>Unfortunately I haven't programmed in Java in
years. So hopefully the little bit I do know can help.<BR><BR>1) The
postgis driver is included in the postgis package which the latest source you
can find here<BR><A
href="http://postgis.refractions.net/download/">http://postgis.refractions.net/download/</A>
(postgis-1.2.1.tar.gz)<BR><BR>2) Here is one thread that shows how to do it
using the driver<BR>a) <A
href="http://postgis.refractions.net/pipermail/postgis-users/2005-June/008542.html">http://postgis.refractions.net/pipermail/postgis-users/2005-June/008542.html</A>
- if you want to use the driver<BR><BR>I think the driver is mostly used for
reading geometries rather than setting them or for setting complex
geometries.<BR><BR>b) Using a more elegant variant of what I mentioned.
This one doesn't use the postgis driver but just a plain postgresql
driver<BR><BR><A
href="http://postgis.refractions.net/pipermail/postgis-users/2006-October/013484.html">http://postgis.refractions.net/pipermail/postgis-users/2006-October/013484.html</A><BR><BR><BR>So
basically your logic in this case would look like<BR><BR>PreparedStatement stmt
= con.prepareStatement("insert into ais (mmsi, the_geom) " + "values(?,
GeometryFromText(?,-1))");<BR>stmt.setString(1, “abc”);<BR>stmt.setString(2,
"POINT(" + lat + " " + lon +
")");<BR>System.out.println(stmt);<BR>stmt.executeUpdate();<BR><BR>Hope that
helps,<BR>Regina<BR><BR><BR>________________________________<BR><BR>From:
postgis-users-bounces@postgis.refractions.net [<A
href="mailto:postgis-users-bounces@postgis.refractions.net">mailto:postgis-users-bounces@postgis.refractions.net</A>]
On Behalf Of Malm Paul<BR>Sent: Wednesday, March 14, 2007 9:48 AM<BR>To: PostGIS
Users Discussion<BR>Subject: [postgis-users] populatong a postgis via
Javaappl.<BR><BR><BR><BR>I would like to insert a point in a postgis
database.<BR><BR>BEGIN;<BR>INSERT INTO "public"."ais" ("mmsi",
the_geom)<BR>VALUES ('123', ,GeometryFromText('POINT(-73.910977172366
40.729270630126)',-1));<BR>END;<BR><BR>This is what I have tried in
java.<BR><BR>static private Connection con = null;<BR>double lat
63.049813568477724;<BR>double lon
20.26472335111486;<BR><BR>Class.forName(org.postgresql.Driver);<BR>con =
DriverManager.getConnection(“jdbc:postgresql:postgis”, “username”,
“pw”);<BR>PreparedStatement stmt = con.prepareStatement("insert into ais (mmsi,
the_geom) " + "values(?, ?)");<BR>stmt.setString(1,
“abc”);<BR>stmt.setString(2, "GeometryFromText('POINT(" + lat + " " + lon +
")',-1)");<BR>System.out.println(stmt);<BR>stmt.executeUpdate();<BR><BR>This is
what System.out.println prints:<BR>insert into ais (mmsi, the_geom)
values(abc, GeometryFromText('POINT(63.049813568477724
20.26472335111486)',-1))<BR><BR>This is the Error
message<BR>org.postgresql.util.PSQLException: ERROR: column "the_geom" is of
type geometry but expression is of type character varying<BR><BR><BR><BR>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).<BR><BR>This
must be a basic thing, but I don’t get
it…<BR><BR>Thanks..<BR><BR><BR><BR>________________________________<BR><BR><BR><BR>The
substance of this message, including any attachments, may be<BR>confidential,
legally privileged and/or exempt from disclosure<BR>pursuant to Massachusetts
law. It is intended solely for the<BR>addressee. If you received this in error,
please contact the sender<BR>and delete the material from any
computer.<BR><BR><BR></FONT></P></DIV>
</BODY>
</HTML>