2016-10-02 383 views
0

我在使用JDBC調用PostgreSQL函數時遇到問題,情況如下。存儲功能endpoint_organizations的定義是這樣的:通過JDBC執行PostgreSQL存儲函數時出現異常「函數不存在」

postgres=# \df public.endpoint_organizations 
              List of functions 
Schema |   Name   |    Result data type    | Argument data types | Type 
--------+------------------------+------------------------------------------+---------------------+-------- 
public | endpoint_organizations | TABLE(organizationid integer, name text) | staffid1 integer | normal 
(1 row) 

我從Java調用它是這樣的:

int staffId = 1 
PreparedStatement endpointOrganizations = connection.prepareStatement("SELECT * FROM endpoint_organizations (?)"); 
endpointOrganizations.setInt(1, staffId); 
ResultSet resultSet = endpointOrganizations.executeQuery(); 

我收到此異常:

org.postgresql.util.PSQLException: 
ERROR: function endpoint_organizations(integer) does not exist 
Hint: No function matches the given name and argument types. You might need to add explicit type casts. 
Position: 15 

可能是什麼原因?如果我沒有弄錯,那以前就行得通了。我現在已經重複檢查和三重檢查,但沒有看到可能導致問題的原因。

+0

您是否有權限使用jdbc用戶執行該功能?如果不授予對功能endpoint_organizations的執行; – d1ll1nger

+0

@ d1ll1nger是的,我有。如果我'psql -U '到數據庫中並且'select * from endpoint_organizations(1)'那裏,事情工作正常。 – Drux

回答

1

這當然是我的一個愚蠢的錯誤。在連接到PostgreSQL後,我用psql -U <user>而不是psql -U <user> <database>,即更新受影響的數據庫postgres而不是<database>,而JDBC連接到<database>後,我也對存儲的函數進行了最近的更新。

在對正確的數據庫執行更新後,事情現在恢復正常。