简体   繁体   English

错误:未为存储过程定义参数输出

[英]Error: Parameter out was not defined for stored procedure

When I call this stored procedure: 当我调用此存储过程时:

procedure [dbo].[pTest]
     @Date varchar(max) =null
as
begin
select * from test
end

from java using Spring Data JPA 1.10.2 with com.microsoft.sqlserver's sqljdbc 4.2. 从Java使用Spring Data JPA 1.10.2和com.microsoft.sqlserver的sqljdbc 4.2一起使用。 I get no error. 我没有错。 But when I add another parameter to the procedure 但是当我向过程添加另一个参数时

procedure [dbo].[pTest]
     @ReportData varbinary(max) out
     ,@Date varchar(max) =null
as
begin
select * from test
end

I get the following error: 我收到以下错误:

2016-10-06 15:50:16.283 DEBUG 32604 --- [           main] c.m.s.jdbc.internals.SQLServerException  : *** SQLException:SQLServerCallableStatement:9 com.microsoft.sqlserver.jdbc.SQLServerException: Parameter out was not defined for stored procedure pTest. Parameter out was not defined for stored procedure pTest.
2016-10-06 15:50:16.289 DEBUG 32604 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : Error preparing CallableStatement [pTest]

com.microsoft.sqlserver.jdbc.SQLServerException: Parameter out was not defined for stored procedure pTest.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191) ~[sqljdbc-4.2.jar:na]

If I remove the @Date parameter and modify the code accordingly, I get no error. 如果删除@Date参数并相应地修改代码,则不会出错。 Once I add back the @Date parameter to have two parameters, I get the error again. 一旦我将@Date参数添加回具有两个参数,我将再次收到错误。 Why? 为什么?

The code for two params is as follows: 两个参数的代码如下:

@Entity
@NamedStoredProcedureQuery(name = "Test.getTest", procedureName = "pTest", parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, name = "Date", type = String.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, name = "ReportData", type = byte[].class)
          })
public class Test {

    // serves no purpose other than to meet
    // JPA requirement
    @Id
    private byte[] reportData;
}

Spring data repository: Spring数据存储库:

public interface TestRepository  extends Repository<Test, Long> {
    @Procedure("pTest")
    byte[] get(@Param("Date") String date);
}

Test code: 测试代码:

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional(transactionManager="transactionManager")
public class TestRepositoryTest {

    @Autowired
    private TestRepository testRepository;

    @Test
    public void testGet() throws SQLException {

        byte[] blob = testRepository.get("hi");
        //error occurs
    }

}

Found the issue :) The attribute name of @NamedStoredProcedureQuery needs to match the repository method name. 发现了问题:) @NamedStoredProcedureQuery的属性名称需要与存储库方法名称匹配。 So change this: 所以改变这个:

@Entity
@NamedStoredProcedureQuery(name = "Test.getTest", procedureName = "pTest", parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, name = "Date", type = String.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, name = "ReportData", type = byte[].class)
          })

to this: 对此:

@Entity
@NamedStoredProcedureQuery(name = "Test.get", procedureName = "pTest", parameters = {
        @StoredProcedureParameter(mode = ParameterMode.IN, name = "Date", type = String.class),
        @StoredProcedureParameter(mode = ParameterMode.OUT, name = "ReportData", type = byte[].class)
          })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过CallableStatement调用存储过程时出现“参数不是OUT参数”错误 - “Parameter is not an OUT parameter” error while calling stored procedure via CallableStatement 从Java(Eclipse)调用MySQL存储过程中的OUT参数错误 - OUT Parameter Error in Calling MySQL Stored Procedure from Java (Eclipse) MySQL Java 存储过程给出错误“参数索引 1 超出范围” - MySQL Java stored procedure gives error "Parameter index of 1 is out of range" JDBI支持带out参数的存储过程 - JDBI supports stored procedure with out parameter 无法访问存储过程的OUT参数 - Unable to access stored procedure's OUT parameter Java存储过程中需要使用OUT参数的MYSQL - needed in java stored procedure with OUT parameter for MYSQL JDBC MySQL存储过程抛出异常“参数编号2不是OUT参数”吗? - JDBC MySQL stored procedure throw exception “ Parameter number 2 is not an OUT parameter”? 使用 VARRAY 或用户定义类型作为 IN 参数的 Oracle 存储函数/过程 - Oracle stored function/procedure with VARRAY or user-defined type as IN parameter 未为存储过程定义参数@ x…使用MS_SQL JDBC - Parameter @x was not defined for stored procedure… with MS_SQL JDBC Mybatis在执行存储过程时无法设置OUT参数 - Mybatis could not set OUT parameter when executing stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM