[postgis-users] enforce_dims_geom error (JDBC)
Just van den Broecke
just at justobjects.nl
Wed Oct 4 21:32:19 PDT 2006
Hi,
I have a problem using INSERT of POINTs in a geometry column defined by
AddGeometryColumn() with dimension 0. The error is:
Aborted due to error:
org.postgresql.util.PSQLException: ERROR: new row for relation
"latlon_test" violates check constraint "enforce_dims_geom"
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:340)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:332)
at examples.TestLatLon.main(TestLatLon.java:57)
Below is the program I use. Standard examples that use only "geometry"
columns, i.e. no AddGeometryColumn (like TestServer.java from postgis
JDBC) work OK. pgadmin III shows geometry_columns with dimension 0 etc.
I tried using the wrapper Drivers but to no avail. I may be missing out
some important point. Below the program is also my PG/Postgis version
info. (in short: use Mac OS X 10.4.7 DarwinPorts PG 8.1.3 with Postgis
1.1.1)
Thanks for any help.
--Just
Just van den Broecke just at justobjects.nl
Just Objects B.V. tel +31 65 4268627 Skype: justb4
The Netherlands http://www.justobjects.nl
------------------------ program ------------------
public class TestLatLon {
public static void main(String[] args) {
// String dburl = "jdbc:postgresql://localhost:5432/gistest";
String dburl = "jdbc:postgresql_lwgis://localhost:5432/gistest";
// String driverClass = "org.postgresql.Driver";
String driverClass = "org.postgis.DriverWrapperLW";
String dbuser = "oaseuser";
String dbpass = "*****";
String dropSQL = "drop table latlon_test";
String createSQL = "create table latlon_test (id int4); ";
String addgeom = "SELECT AddGeometryColumn('gistest',
'latlon_test','geom', 4326,'POINT',0)";
String dropGeom = "SELECT DropGeometryColumn('gistest',
'latlon_test','geom')";
String insertPointSQL = "INSERT INTO latlon_test values (10,
GeomFromText('POINT (4.92 52.35)', 4326) )";
try {
p("Creating JDBC connection...");
Class.forName(driverClass);
Connection conn = DriverManager.getConnection(dburl,
dbuser, dbpass);
p("connection class==" + conn.getClass().getName());
Statement s = conn.createStatement();
p("Creating table with geometric types...");
try {
// table might exist
s.execute(dropGeom);
s.execute(dropSQL);
} catch (Exception e) {
p("Error dropping table: " + e.getMessage());
}
p("Create table...");
s.execute(createSQL);
p("Adding geometric types...");
s.execute(addgeom);
p("Inserting point...");
s.execute(insertPointSQL);
s = conn.createStatement();
p("Querying table...");
// ResultSet r = s.executeQuery("select asText(geom),id
from " + dbtable);
ResultSet r = s.executeQuery("select geom,id from
test_latlon");
while (r.next()) {
Object obj = r.getObject(2);
//PGgeometry obj = (PGgeometry)r.getObject(1);
int id = r.getInt(1);
p("Row " + id + ":");
p("obj: class=" + obj.getClass().getName() + " s=" +
obj.toString());
}
s.close();
conn.close();
} catch (Exception e) {
System.err.println("Aborted due to error:");
e.printStackTrace();
System.exit(1);
}
}
public static void p(String s) {
System.out.println(s);
}
}
---------- Version info --------------
** PostGIS jdbc client code **
getFullVersion: PostGIS JDBC V1.1.0
** PGJDBC Driver **
getVersion: PostgreSQL 8.1 JDBC3 with SSL (build 407)
getMajorVersion: 8
getMinorVersion: 1
** PostgreSQL Server **
version: PostgreSQL 8.1.3 on i686-apple-darwin8.7.1, compiled by
GCC i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build
5363)
** PostGIS Server **
postgis_version: 1.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
postgis_proj_version: Rel. 4.4.9, 29 Oct 2004
postgis_scripts_installed: 1.1.1
postgis_lib_version: 1.1.1
postgis_scripts_released: 1.1.1
postgis_uses_stats: t
postgis_geos_version: 2.2.1-CAPI-1.0.1
postgis_scripts_build_date: 2006-10-04 08:22:06
postgis_lib_build_date: 2006-10-04 08:22:06
postgis_full_version: POSTGIS="1.1.1" GEOS="2.2.1-CAPI-1.0.1"
PROJ="Rel. 4.4.9, 29 Oct 2004" USE_STATS
More information about the postgis-users
mailing list