[postgis-users] populatong a postgis via Javaappl.

Malm Paul paul.malm at saabgroup.com
Wed Mar 14 00:55:20 PDT 2007


Hello
Im having a problem with populating a Postgis db with geographical
objects via an java application.

I'm trying to do this:
BEGIN;
INSERT INTO "public"."AIS_ships"
("mmsi","rxtime","latitude","longitude","sortkey","sog","cog","heading",
"timetag","lat","lon","shiptype","shipname",ship_geom) 
VALUES
('0DB8B5E8','1173856992750','0240F216','00B96F5E','0.005326913158112814'
,'093','
089','00E','01','1.0998689700278892','0.3535068406805592','ss','
ss',GeometryFromText('POINT(-73.910977172366 40.729270630126)',-1));
END;


This is the java code:
PreparedStatement stmt = con
.prepareStatement("insert into ais (mmsi, rxtime, latitude, longitude,
sortkey, sog, cog, heading, timetag, lat, lon, shiptype, shipname,
the_geom) "
		+ "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setString(1, sentence[2]);
stmt.setLong(2, System.currentTimeMillis());
stmt.setString(3, sentence[5]);
stmt.setString(4, sentence[6]);
double lat = Long.decode("0x" + sentence[5]).doubleValue() /
34377467.70785;
double lon = Long.decode("0x" + sentence[6]).doubleValue() /
34377467.70785;
stmt.setString(6, sentence[7]);
stmt.setString(7, sentence[8]);
stmt.setString(8, sentence[9]);
stmt.setString(9, sentence[10]);
stmt.setDouble(10, lat);
stmt.setDouble(11, lon);
stmt.setString(12, sentence[11]);
stmt.setString(13, sentence[12]);
stmt.setString(14, "GeometryFromText('POINT(" + lat*180/3.14 + " " +
lon*180/3.14 + ")',-1)");
System.out.println(stmt);
stmt.executeUpdate();

This is what System.out.println prints:
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))

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

Could someone please tell me how to do this correct?

Paul Malm
Saab Systems, Naval Systems Division
Tel: +46 8 580 838 22
Mobile: +46 734 373 822


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


More information about the postgis-users mailing list