procedure myProcedure (text, text) does not exist 提示:没有过程匹配给定的名称和参数类型
procedure myProcedure (text, text) does not exist Hint: No procedure matches the given name and argument types
每当尝试从我的 java 应用程序调用 PostgreSQL 11.4 中的任何存储过程但遇到此问题时 procedure pkg$my_procedure(text, text) does not exist
。请注意,我可以从 DB 调用 SP。
我正在使用 PostgreSQL JDBC 版本 42.2.16
SP 声明
create procedure pkg$my_procedure(i_param_name text, i_param_2 text, INOUT o_object refcursor)
language plpgsql
as
$$
BEGIN
// myLogic
Java调用SP的代码
Connection con = null;
CallableStatement callableStatement = null;
ResultSet rs = null;
Object obj = null;
try {
con = eRestaurantConnection.getConnetion();
callableStatement = con.prepareCall("call pkg$my_procedure(cast(? as text),cast(? as text),?)");
callableStatement.setString(1, string1);
callableStatement.setString(2, string2);
callableStatement.registerOutParameter(3, Types.REF_CURSOR);
callableStatement.execute();
rs = (ResultSet) callableStatement.getObject(3);
obj = fillObjectInfo(rs);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
} finally {
if (rs != null)
rs.close();
if(callableStatement!=null)callableStatement.close();
if(con!=null)con.close();
}
return obj;
异常
ERROR: procedure pkg$my_procedure(text, text) does not exist
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts.
Position: 6
org.postgresql.util.PSQLException: ERROR: procedure pkg$my_procedure(text, text) does not exist
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts.
Position: 6
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
at org.postgresql.jdbc.PgCallableStatement.executeWithFlags(PgCallableStatement.java:83)
at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.performQueryExecutionListener(StatementProxyLogic.java:310)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.access0(StatementProxyLogic.java:36)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.execute(StatementProxyLogic.java:122)
at net.ttddyy.dsproxy.listener.MethodExecutionListenerUtils.invoke(MethodExecutionListenerUtils.java:41)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.invoke(StatementProxyLogic.java:119)
at net.ttddyy.dsproxy.proxy.jdk.CallableStatementInvocationHandler.invoke(CallableStatementInvocationHandler.java:36)
...
来自 PostgreSQL 的调用
do $$
declare
result refcursor = 'generated_result_cursor';
rec record;
begin
open result for call pkg$my_procedure(i_param_name := 'name', i_param_2 := 'param', o_object := null);
LOOP
FETCH from result into rec;
EXIT WHEN NOT FOUND;
raise notice 're: %',rec;
EXIT;
END LOOP;
end
$$;
您创建的存储过程没有用双引号引起来,因此它以小写形式存储。
错误消息报告包含大写字母的函数名。由于PG区分大小写,存储过程没有找到
--> 使用小写函数名
callableStatement = con.prepareCall("call myprocedure(cast(? as text),cast(? as text),?)");
这一点都需要在上面的代码中修正。感谢@JGH 找到第一期。
- 您需要确保大小写匹配。
- 即使用于输出也需要设置所有参数。如果有输出需要将它们设置为空。
- 最后要做的是禁用auto-commit。
Java 代码调用 SP
Connection con = null;
con.setAutoCommit(false);
CallableStatement callableStatement = null;
ResultSet rs = null;
Object obj = null;
try {
con = eRestaurantConnection.getConnetion();
callableStatement = con.prepareCall("call pkg$my_procedure(cast(? as text),cast(? as text),?)");
callableStatement.setString(1, string1);
callableStatement.setString(2, string2);
callableStatement.setNull(3, Types.OTHER);
callableStatement.registerOutParameter(3, Types.REF_CURSOR);
callableStatement.execute();
rs = (ResultSet) callableStatement.getObject(3);
obj = fillObjectInfo(rs);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
} finally {
if (rs != null)
rs.close();
if(callableStatement!=null)callableStatement.close();
if(con!=null)con.close();
}
return obj;
每当尝试从我的 java 应用程序调用 PostgreSQL 11.4 中的任何存储过程但遇到此问题时 procedure pkg$my_procedure(text, text) does not exist
。请注意,我可以从 DB 调用 SP。
我正在使用 PostgreSQL JDBC 版本 42.2.16
SP 声明
create procedure pkg$my_procedure(i_param_name text, i_param_2 text, INOUT o_object refcursor)
language plpgsql
as
$$
BEGIN
// myLogic
Java调用SP的代码
Connection con = null;
CallableStatement callableStatement = null;
ResultSet rs = null;
Object obj = null;
try {
con = eRestaurantConnection.getConnetion();
callableStatement = con.prepareCall("call pkg$my_procedure(cast(? as text),cast(? as text),?)");
callableStatement.setString(1, string1);
callableStatement.setString(2, string2);
callableStatement.registerOutParameter(3, Types.REF_CURSOR);
callableStatement.execute();
rs = (ResultSet) callableStatement.getObject(3);
obj = fillObjectInfo(rs);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
} finally {
if (rs != null)
rs.close();
if(callableStatement!=null)callableStatement.close();
if(con!=null)con.close();
}
return obj;
异常
ERROR: procedure pkg$my_procedure(text, text) does not exist
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts.
Position: 6
org.postgresql.util.PSQLException: ERROR: procedure pkg$my_procedure(text, text) does not exist
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts.
Position: 6
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
at org.postgresql.jdbc.PgCallableStatement.executeWithFlags(PgCallableStatement.java:83)
at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.performQueryExecutionListener(StatementProxyLogic.java:310)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.access0(StatementProxyLogic.java:36)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.execute(StatementProxyLogic.java:122)
at net.ttddyy.dsproxy.listener.MethodExecutionListenerUtils.invoke(MethodExecutionListenerUtils.java:41)
at net.ttddyy.dsproxy.proxy.StatementProxyLogic.invoke(StatementProxyLogic.java:119)
at net.ttddyy.dsproxy.proxy.jdk.CallableStatementInvocationHandler.invoke(CallableStatementInvocationHandler.java:36)
...
来自 PostgreSQL 的调用
do $$
declare
result refcursor = 'generated_result_cursor';
rec record;
begin
open result for call pkg$my_procedure(i_param_name := 'name', i_param_2 := 'param', o_object := null);
LOOP
FETCH from result into rec;
EXIT WHEN NOT FOUND;
raise notice 're: %',rec;
EXIT;
END LOOP;
end
$$;
您创建的存储过程没有用双引号引起来,因此它以小写形式存储。
错误消息报告包含大写字母的函数名。由于PG区分大小写,存储过程没有找到
--> 使用小写函数名
callableStatement = con.prepareCall("call myprocedure(cast(? as text),cast(? as text),?)");
这一点都需要在上面的代码中修正。感谢@JGH 找到第一期。
- 您需要确保大小写匹配。
- 即使用于输出也需要设置所有参数。如果有输出需要将它们设置为空。
- 最后要做的是禁用auto-commit。
Java 代码调用 SP
Connection con = null;
con.setAutoCommit(false);
CallableStatement callableStatement = null;
ResultSet rs = null;
Object obj = null;
try {
con = eRestaurantConnection.getConnetion();
callableStatement = con.prepareCall("call pkg$my_procedure(cast(? as text),cast(? as text),?)");
callableStatement.setString(1, string1);
callableStatement.setString(2, string2);
callableStatement.setNull(3, Types.OTHER);
callableStatement.registerOutParameter(3, Types.REF_CURSOR);
callableStatement.execute();
rs = (ResultSet) callableStatement.getObject(3);
obj = fillObjectInfo(rs);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
} finally {
if (rs != null)
rs.close();
if(callableStatement!=null)callableStatement.close();
if(con!=null)con.close();
}
return obj;