<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>populatong a postgis via Javaappl.</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2>I think since you are using setString its probably trying
to stuff the string</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2>GeometryFromText....</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2>In the_geom field instead of the geometry returned by
GeometryFromText ...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2>2 choices come to mind</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2>1) Don't put the last in as a prepared parameter - but
instead do something like</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
size=2>con</FONT><SPAN lang=en-us><FONT face=Arial
size=2>.prepareStatement("insert into ais (mmsi, rxtime, latitude, longitude,
sortkey, sog, cog, heading, timetag, lat, lon, shiptype, shipname, the_geom) "
</FONT></SPAN><SPAN lang=en-us><FONT face=Arial size=2>+ "values(?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, <SPAN
class=560375311-14032007>GeometryFromText('POINT(" + lat*180/3.14 + " " +
lon*180/3.14 + ")',-1)"</SPAN>);</FONT></SPAN></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><SPAN lang=en-us><FONT
face=Arial size=2></FONT></SPAN></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><SPAN lang=en-us><FONT
face=Arial size=2>or </FONT></SPAN></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><SPAN lang=en-us><FONT
face=Arial size=2>2) Use one of the PostGis JDBC drivers instead of a simple
PostGreSQL jdbc driver. I think those ones have PGObject and so
forth. </FONT></SPAN></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=560375311-14032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B>
postgis-users-bounces@postgis.refractions.net
[mailto:postgis-users-bounces@postgis.refractions.net] <B>On Behalf Of </B>Malm
Paul<BR><B>Sent:</B> Wednesday, March 14, 2007 3:55 AM<BR><B>To:</B>
postgis-users@postgis.refractions.net<BR><B>Subject:</B> [postgis-users]
populatong a postgis via Javaappl.<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format -->
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial
size=2>Hello</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>Im having a problem with
populating a Postgis db with geographical objects</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2> via an java
application.</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2>I'm
trying to do this</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN lang=en-us><FONT
face=Arial size=2>:</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=en-us></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>BEGIN;</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>INSERT INTO
"public"."AIS_ships"
("mmsi","rxtime","latitude","longitude","sortkey","sog","cog","heading","timetag","lat","lon","shiptype","shipname",ship_geom)
</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>VALUES
('0DB8B5E8','1173856992750','0240F216','00B96F5E','0.005326913158112814','093','
089','00E','01','1.0998689700278892','0.3535068406805592',</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2>’</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2>ss</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2>','
ss',GeometryFromText('POINT(-73.910977172366
40.729270630126)',-1));</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>END;</FONT></SPAN></P><BR>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>This is the java
code:</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>PreparedStatement stmt =
con</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>.prepareStatement("insert
into ais (mmsi, rxtime, latitude, longitude, sortkey, sog, cog, heading,
timetag, lat, lon, shiptype, shipname, the_geom) "</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us>
<FONT face=Arial size=2>+ "values(?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(1,
sentence[2]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setLong(2,
System.currentTimeMillis());</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(3,
sentence[5]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(4,
sentence[6]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>double lat =
Long.decode("0x" + sentence[5]).doubleValue() /
34377467.70785;</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>double lon =
Long.decode("0x" + sentence[6]).doubleValue() /
34377467.70785;</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(6,
sentence[7]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(7,
sentence[8]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(8,
sentence[9]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setString(9,
sentence[10]);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setDouble(10,
lat);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>stmt.setDouble(11,
lon);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN><SPAN lang=sv><FONT
face=Arial size=2>stmt.setString(12,</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=en-us> <FONT face=Arial size=2>sentence[1</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2>1</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial size=2>]</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us></SPAN><SPAN lang=sv><FONT face=Arial
size=2>);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=sv><FONT face=Arial
size=2>stmt.setString(13,</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN lang=en-us>
<FONT face=Arial size=2>sentence[1</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=en-us><FONT face=Arial size=2>2</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=en-us><FONT face=Arial size=2>]</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=sv><FONT face=Arial size=2>);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us><FONT face=Arial
size=2>stmt.setString(14, "GeometryFromText('POINT(" + lat*180/3.14 + " " +
lon*180/3.14 + ")',-1)");</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial
size=2>System.out.println(stmt);</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial
size=2>stmt.executeUpdate();</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>This is
what</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN lang=en-us> <FONT face=Arial
size=2>System.out.p</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN lang=en-us><FONT
face=Arial size=2>rintln prints:</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>insert into ais (mmsi,
rxtime, latitude, longitude, sortkey, sog, cog, heading, timetag, lat, lon,
shiptype, shipname, the_geom) values(0DB8B5E8, 1173856992750, 0240F216,
00B96F5E, 0.005326913158112814, 093, 089, 00E, 01, 1.0998689700278892,
0.3535068406805592, ss, ss, GeometryFromText('POINT(63.049813568477724
20.26472335111486)',-1))</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>This is the
errormessage</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial
size=2>org.postgresql.util.PSQLException: ERROR: column "the_geom" is of type
geometry but expression is of type character varying</FONT></SPAN><SPAN
lang=en-us></SPAN><SPAN lang=en-us></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN></P>
<P dir=ltr><SPAN lang=en-us><FONT face=Arial size=2>Could someone please tell me
how to do this correct?</FONT></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=en-us></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=sv-se></SPAN><A name=""><SPAN lang=sv-se></SPAN></A></P>
<P dir=ltr><SPAN lang=en-us><B></B></SPAN><SPAN
lang=en-us><B></B></SPAN><B><SPAN lang=sv-se><FONT face=Arial size=2>Paul
Malm</FONT></SPAN></B></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=sv-se><FONT face=Arial size=2>Saab Systems, Naval Systems
Division</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=sv-se><FONT face=Arial size=2>Tel: +46 8 580 838 22</FONT></SPAN></P>
<P dir=ltr><SPAN lang=sv-se><FONT face=Arial size=2>Mobile: +46 734 373
822</FONT></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN><SPAN lang=en-us></SPAN><SPAN
lang=sv-se></SPAN></P>
<P dir=ltr><SPAN lang=en-us></SPAN></P></BODY></HTML>
<HTML><BODY><P><hr size=1></P><br>
<P><STRONG><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>
</STRONG></P></BODY></HTML>