Java 过程myProcedure(text,text)不存在提示:没有与给定名称和参数类型匹配的过程

Java 过程myProcedure(text,text)不存在提示:没有与给定名称和参数类型匹配的过程,java,postgresql,stored-procedures,Java,Postgresql,Stored Procedures,无论何时尝试从我的java应用程序调用PostgreSQL 11.4中的任何存储过程,但得到这个问题过程pkg$my_proceduretext,文本都不存在。请注意,我可以从DB调用SP im使用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 $$

无论何时尝试从我的java应用程序调用PostgreSQL 11.4中的任何存储过程,但得到这个问题过程pkg$my_proceduretext,文本都不存在。请注意,我可以从DB调用SP

im使用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
调用SP的Java代码

        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;
        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;
例外

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.access$700(StatementProxyLogic.java:36)
    at net.ttddyy.dsproxy.proxy.StatementProxyLogic$1.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),?)");

您创建的存储过程没有双重引用名称,因此它以小写形式存储

错误消息报告包含大写字母的函数名。由于PG区分大小写,因此找不到存储过程

->使用小写的函数名

callableStatement = con.prepareCall("call myprocedure(cast(? as text),cast(? as text),?)");

所有这一点都需要在上述代码中修复。感谢@JGH找到第一期

您需要确保案例匹配。 即使用于输出,也需要设置all参数。如果有输出,则需要将其设置为null。 最后要做的事情是禁用自动提交。 调用SP的Java代码

        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;
        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;

所有这一点都需要在上述代码中修复。感谢@JGH找到第一期

您需要确保案例匹配。 即使用于输出,也需要设置all参数。如果有输出,则需要将其设置为null。 最后要做的事情是禁用自动提交。 调用SP的Java代码

        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;
        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;

不相关,但是:如果要返回结果,请使用函数。过程并不是为此而设计的。请注意,我可以从数据库调用SP。请给出一个例子。@a_horse_,没有名字,我完全同意,但这是一个老项目,我们只是从Oracle迁移到PostgreSQL@jjanes更新问题以包含来自PostgreSQLUnrelated的调用,但是:如果要返回结果,使用函数。过程并不是为此而设计的。请注意,我可以从数据库调用SP。请给出一个例子。@a_horse_,没有名字,我完全同意,但这是一个老项目,我们只是从Oracle迁移到PostgreSQL@jjanes更新问题以包含PostgreSql的调用,该调用也是添加callableStatement.setNull3所必需的,类型。其他;即使这是一个输出。另外,将其注册为添加callableStatement.setNull3、Types.OTHER所需的输出;即使这是一个输出。另外,将其注册为输出