次のクエリは、pgAdmin の SQL コンソールで機能します。
insert into sometable values (DEFAULT,9, 'test content', '(-194.0, 53.0)', '(+144.345345, -453.043534)', '2012-08-24 14:00:00 +02:00', '2012-08-24 14:00:00 +02:00');
サーバーに送信される値は次のとおりです。
nameValuePair.add(new BasicNameValuePair("userid", "9"));
nameValuePair.add(new BasicNameValuePair("content", "test content"));
nameValuePair.add(new BasicNameValuePair("location1", "(-194.0, 53.0)"));
nameValuePair.add(new BasicNameValuePair("location2", "(+134.350, -433.04345)"));
nameValuePair.add(new BasicNameValuePair("date1", "2012-08-24 14:00:00 +02:00"));
nameValuePair.add(new BasicNameValuePair("date2", "2012-08-24 14:00:00 +02:00"));
PreparedStatement (サーバー上)
psInsert = conn.prepareStatement("insert into OFFERS (USERID, CONTENT, LOCATION1, LOCATION2, DATE1, DATE2) values (?, ?, ?, ?, ?, ?)");
psInsert.setInt(1, userid);
psInsert.setString(2, content);
psInsert.setString(3, location1);
psInsert.setString(4, location);
psInsert.setString(5, date1);
psInsert.setString(6, date2);
psInsert.executeUpdate();
次のエラーが発生します。
org.postgresql.util.PSQLException: ERROR: column "location1" is of type point but expression is of type character varying
**strong text**Hint: You will need to rewrite or cast the expression.
他のいくつかの関連記事 (Postgresql db に GeoSpatial/Point 値を挿入する方法について) を読みましたが、この問題を解決できませんでした。事前に助けに感謝します。