PostgreSQL insertion point value (geometry) using JDBC

Please give me a sample code for inserting records containing an SQL statement:

insert into TABLE (id, value1, value2, point, value3) values (1,'A', 'M', POINT (13.45646, 56.61782),5); 

in JDBC / Postgresql code.

If anyone has a PreparedStatement solution or any other useful solution, it is welcome!

+7
source share
1 answer

At the simplest level, you can create a prepared statement using geometry constructors to pass parameters.

 insert into "TABLE"(id, value1, value2, point, value3) values(1, $1, $2, ST_SetSRID(ST_MakePoint($3, $4), 4326)), $5); 

Where $3 and $4 are longitude and latitude.

See also the PostGIS documentation for the JDBC interface .

+4
source

All Articles