我正在尝试使用Spring JDBC将数据插入postgres(postgis)数据库,但收到以下错误:
# Determine if a path exists and is a directory.
- name: check directory existance and characteristics
stat: path=/path1
register: p1
# both that p.stat.isdir actually exists, and also that it's set to true.
- debug: msg="Path exists"
when: p1.stat.isdir is defined
- debug: msg="This is a directory"
when: p1.stat.isdir
- file: path=/path1 owner='user1' group='group1' mode=0755 state=directory
when: p1.stat.pw_name != 'user1' or p1.stat.gr_name != 'group1' or p1.stat.mode != '0755'
我使用Preparestatement setObject方法设置posgis数据类型。
org.postgresql.util.PSQLException: ERROR: Geometry has Z dimension but column does not
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363)
at com.springjdbc.jdbc.EutranCellGeoComputedInfoDAOImpl.save(EutranCellGeoComputedInfoDAOImpl.java:33)
at com.springjdbc.jdbc.SpringMain.main(SpringMain.java:48)
表:
ps.setObject(2, cityinfo.getCellShape().toString(),java.sql.Types.OTHER);
ps.setObject(3, cityinfo.getCellLocation().toString(),java.sql.Types.OTHER);
需要帮助来解决此问题,还是有其他方法可以使用Spring JDBC保存postgis数据类型。
答案 0 :(得分:3)
查看错误消息:
org.postgresql.util.PSQLException:错误:几何有Z维,但 列不
这意味着,您尝试在仅接受2D数据的列中插入Z坐标数据。
如果您的所有数据都有Z坐标,只需更改为表格即可使用MultiPolygonZ
和PointZ
代替MultiPolygon
和Point
CREATE TABLE area_details_table
(
area geography(MultiPolygonZ,4326),
location geography(PointZ,4326),
calculated_cell_radius numeric(8,2),
latitude numeric(9,6),
longitude numeric(9,6),
id smallint
);
当然,如果您有混合数据,部分使用Z坐标,部分不使用,则无效。在这种情况下,您可以使用完全动态的几何/地理列,这意味着没有几何类型:
CREATE TABLE area_details_table
(
area geography,
location geography,
calculated_cell_radius numeric(8,2),
latitude numeric(9,6),
longitude numeric(9,6),
id smallint
);