Spring JdbcTemplate update Postgis geography column

泄露秘密 提交于 2019-12-11 13:42:18

问题


I'm trying to update the Postgis geography column with Lon and Lat with the code below

public void updateGeoLocation(String lat, String lon) {
    template.update(
            "UPDATE property set geo = ST_GeomFromText('POINT(? ?)', 4326) where id = 'b15e7a7e-3b27-4a2f-b312-33ebbed594b5'",
            lon, lat);
}

But I get the following exception

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [UPDATE property set geo = ST_GeomFromText('POINT(? ?)', 4326) where id = 'b15e7a7e-3b27-4a2f-b312-33ebbed594b5']; The column index is out of range: 1, number of columns: 0.; nested exception is org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.

I tried the following query manually and it works, but I am having issues getting it to work with JdbcTemplate

update property set geo = ST_GeomFromText('POINT(-71.060316 48.432044)', 4326) where id = 'b15e7a7e-3b27-4a2f-b312-33ebbed594b5'

How can I update/insert lon lat for the Postgis geography column using JdbcTemplate?


回答1:


I applied function ST_GeogFromText, and used it like this:

"ST_GeogFromText('SRID=4326;POINT(" + longitude + " " + latitude + ")')"

Notice the difference between ST_GeogFromText and ST_GeomFromText



来源:https://stackoverflow.com/questions/57262202/spring-jdbctemplate-update-postgis-geography-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!