10

Please give me code example to insert records containing 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 solution of PreparedStatement or anyother useful solution it is highly welcomed!

bluish
  • 26,356
  • 27
  • 122
  • 180
Adnan Ali
  • 103
  • 1
  • 1
  • 4

1 Answers1

7

At the simplest level, you can build 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 the longitude and latitude.


See also the PostGIS documentation for the JDBC interface which may be useful with other geometry types (LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon).

Mike T
  • 41,085
  • 18
  • 152
  • 203