如何使用PreparedStatement从java应用程序向Postgresql数据库插入点类型值

如何使用PreparedStatement从java应用程序向Postgresql数据库插入点类型值,java,sql,postgresql,insert,point,Java,Sql,Postgresql,Insert,Point,以下查询在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")); n

以下查询在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"));
以下是发送到服务器的值:

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(在服务器上)

这将导致以下错误:

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数据库中插入地理空间/点值),但没有解决这个问题。提前感谢你的帮助

我将传递实际的
x
y
坐标(或解析服务器上的字符串),并使用
ST_MakePoint

psInsert = conn.prepareStatement(
    "insert into OFFERS (USERID, CONTENT, LOCATION1, LOCATION2, DATE1, DATE2) " + 
    "values (?, ?, ST_MakePoint(?, ?), ST_MakePoint(?, ?), ?, ?)"
);
对于每个
列。

您可以轻松地制作:

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