当前位置: 首页 > 知识库问答 >
问题:

没有与给定的名称和参数类型匹配的函数。您可能需要添加显式类型转换。位置:15::可调用语句Spring

明财
2023-03-14
jdbcTemplate.execute(new CallableStatementCreator() {

                @Override
                public CallableStatement createCallableStatement(final Connection paramConnection)
                        throws SQLException {
                    final CallableStatement cs = paramConnection.prepareCall("{call INSERT_ACP_ASSIGN_FUNCTION(?,?,?)}");
                    cs.setString(1, resourceId); 
                    cs.setInt(2,resourceType); 
                    cs.setArray(3, new PostgreSQLArray(accessControlPolicyIds));
                    return cs;
                }
            }, new CallableStatementCallback() {
                public Object doInCallableStatement(final CallableStatement cs) throws SQLException{
                    cs.execute();
                    return null; 
                }
            });

公共类PostgreSQL Larray实现数组{

private final String[] stringArray;
private final String stringValue;

public PostgreSQLArray(String[] stringArray) {
    this.stringArray = stringArray;
    this.stringValue = stringArrayToPostgreSQLArrayString(stringArray);
}

public String toString() {
    return stringValue;
}

/**
 * 
 * @param inputtedArray source String array
 * @return string representation of a given integer array
 */
    public static String stringArrayToPostgreSQLArrayString(String[] inputtedArray) {
        if ( inputtedArray == null ) {
            return "NULL";
        }
        final int al = inputtedArray.length;
        if ( al == 0 ) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(); 
        sb.append('{');
        for (int i = 0; i < al; i++) {
            if ( i > 0 ) sb.append(',');
            sb.append(inputtedArray[i]);
        }
        sb.append('}');
        return sb.toString();
    }


    public Object getArray() throws SQLException {
        return stringArray == null ? null : Arrays.copyOf(stringArray, stringArray.length);
    }

    public Object getArray(Map<String, Class<?>> map) throws SQLException {
        return getArray();
    }

    public Object getArray(long index, int count) throws SQLException {
        return stringArray == null ? null : Arrays.copyOfRange(stringArray, (int)index, (int)index + count );
    }

    public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
        return getArray(index, count);
    }

    public int getBaseType() throws SQLException {
        return java.sql.Types.INTEGER;
    }

    public String getBaseTypeName() throws SQLException {
        return "varchar";
    }

    public ResultSet getResultSet() throws SQLException {
        throw new UnsupportedOperationException();
    }

    public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public ResultSet getResultSet(long index, int count) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
        throw new UnsupportedOperationException();
    }

    public void free() throws SQLException {
    }

}

CREATE OR REPLACE FUNCTION iot1_0."INSERT_ACP_ASSIGN_FUNCTION"(
    "I_RESOURCE_ID" character varying,
    "I_RESOURCE_TYPE" integer,
    "I_ACP_RESOURCE_ID" character varying[])
  RETURNS void AS
$BODY$ DECLARE
   acp_resource_id character varying;
   acp_id integer;
  BEGIN
    for acp_resource_id in select $3 LOOP
       RAISE NOTICE 'acp_resource_id is %', acp_resource_id;
    select ID into acp_id from iot1_0.ACP_DEFINE where RESOURCEID = acp_resource_id;

    RAISE NOTICE 'acp_id is %', acp_id;
        insert into iot1_0.ACP_ASSIGN(resource_type, acp_id, resource_id) values ($2 , acp_id, $1);
    END LOOP; 
  END;$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION iot1_0."INSERT_ACP_ASSIGN_FUNCTION"(character varying, integer, character varying[])
  OWNER TO enterprisedb;

Sql我在Postgres admin中执行的是

SELECT iot1_0."INSERT_ACP_ASSIGN_FUNCTION"(
    character varying '112w',
     1,
    array['1','2','3']
);

请帮帮我,我对邮局很陌生。我挣扎了很多天。

共有1个答案

麹学文
2023-03-14

是否尝试添加“IOT1_0”到函数调用?您是否从与pgadmin相同的用户运行它?您可能还希望运行列出java代码中可用过程的查询之一,以查看哪些方法应该是可见的。

 类似资料: