【发布时间】:2013-07-31 22:08:26
【问题描述】:
用于 postgres 的最新 Java JDBC 驱动程序声称原生支持 UUID;使用 Postgres 9.2 (mac)。
确实,当使用 PreparedStatement 时,我可以单步执行驱动程序代码,甚至可以步行 通过 AbstractJdbc3gStatement.java 中专门的“setUuid”函数。种种迹象表明,它应该“正常工作”。
但是,它不起作用。数据库抛出一个错误,我因此收到:
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 139
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) ~[postgresql-9.2-1002.jdbc4.jar:na]
是的,确实,JDBC 驱动程序中的 setUuid 确实将其作为字节发送:
private void setUuid(int parameterIndex, UUID uuid) throws SQLException {
if (connection.binaryTransferSend(Oid.UUID)) {
byte[] val = new byte[16];
ByteConverter.int8(val, 0, uuid.getMostSignificantBits());
ByteConverter.int8(val, 8, uuid.getLeastSignificantBits());
bindBytes(parameterIndex, val, Oid.UUID);
} else {
bindLiteral(parameterIndex, uuid.toString(), Oid.UUID);
}
}
什么给了? 实际数据库中是否需要一些魔法符文来加持这种转换?
【问题讨论】:
-
您可以发布您尝试运行的实际 PreparedStatement 吗?
标签: java postgresql jdbc pg-jdbc