2

次のクエリは、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 値を挿入する方法について) を読みましたが、この問題を解決できませんでした。事前に助けに感謝します。

4

2 に答える 2

3

あなたは簡単に作ることができます:

psInsert = conn.prepareStatement(
"insert into OFFERS (USERID, CONTENT, LOCATION1, LOCATION2, DATE1, DATE2) " + 
"values (?, ?, point(?, ?), point(?, ?), ?, ?)" );
于 2013-12-13T16:37:28.013 に答える
2

x実際の座標を渡しy(またはサーバー上の文字列を解析し)、使用しますST_MakePoint

psInsert = conn.prepareStatement(
    "insert into OFFERS (USERID, CONTENT, LOCATION1, LOCATION2, DATE1, DATE2) " + 
    "values (?, ?, ST_MakePoint(?, ?), ST_MakePoint(?, ?), ?, ?)"
);

POINT列ごとに。

于 2013-09-08T13:51:08.137 に答える