问题
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