[postgis-users] populatong a postgis via Javaappl.

Malm Paul paul.malm at saabgroup.com
Wed Mar 14 05:38:57 PDT 2007


I've googled for postgis jdbc drivers bur not found anything.

Is it all wrong to do like this:

 

Class.forname(org.postgis.Driver);

Con.DriverManager.getConnection(jdbc:postgis:dbname, "user",
"password");

 

________________________________

From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Obe,
Regina
Sent: den 14 mars 2007 13:02
To: PostGIS Users Discussion
Subject: RE: [postgis-users] populatong a postgis via Javaappl.

 

I think since you are using setString its probably trying to stuff the
string

 

GeometryFromText....

 

In the_geom field instead of the geometry returned by GeometryFromText
...

 

2 choices come to mind

1) Don't put the last in as a prepared parameter - but instead do
something like

 

con.prepareStatement("insert into ais (mmsi, rxtime, latitude,
longitude, sortkey, sog, cog, heading, timetag, lat, lon, shiptype,
shipname, the_geom) " + "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
GeometryFromText('POINT(" + lat*180/3.14 + " " + lon*180/3.14 +
")',-1)");

 

or 

2) Use one of the PostGis JDBC drivers instead of a simple PostGreSQL
jdbc driver.  I think those ones have PGObject and so forth. 

 

 

 

________________________________

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 3:55 AM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] populatong a postgis via Javaappl.

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

________________________________



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


More information about the postgis-users mailing list