【发布时间】:2013-08-30 18:14:07
【问题描述】:
当我通过psql 运行下面的 sql 语句时,它可以正常工作,但是当我尝试通过使用preparedstatement 构建它来运行相同的查询时,它会失败。
INSERT INTO Hvbp
(provider_number, weighted_clinical_process,
weighted_patience_experience, total_performance_score,
coordinates, latitude, longitude, address, city, state, zip)
VALUES
('010092', 43.909090909091, 13.5, 57.409090909091,
'POINT(33.206201 -87.525480)', 33.206200613000476,
-87.52548020899968, '809 UNIVERSITY BOULEVARD EAST', 'TUSCALOOSA', 'AL', '');
我不断收到的错误是
org.postgresql.util.PSQLException: ERROR: column "coordinates" is of type geography but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 203
coordinates 列的类型为 GEOGRAPHY(POINT)
【问题讨论】:
-
省略
'POINT(33.206201 -87.525480)'周围的单引号。这是一个函数调用,而不是字符串文字 -
@a_horse_with_no_name,这实际上不适用于 Postgres JDBC 驱动程序。
statement.setString(1,"POINT(1 2)");导致投诉ERROR: column "geography" is of type geography but expression is of type character... -
你的SQL语句没有使用参数,这就是我写的原因。对于 PreparedStatement,您需要 SQL 字符串中的
point(?,?)(不带单引号)和 两个setFloat()调用来为每个?提供值 -
ireeder,应该是“POINT”(1,2),而不是“POINT(1 2)”,因为它们是完全不同的东西。
标签: java jdbc gis postgis jdbc-postgres