JDBC SQL Server:未为参数编号设置该值

paw*_*pta 13 java sql-server websphere jdbc sql-server-2012

我从从java代码调用存储过程的代码中收到以下错误:

Exception Trace {} org.springframework.jdbc.UncategorizedSQLException:CallableStatementCallback; 未分类SQL的SQLException [{call test.usp_xxx_GetCompanyDetails(?,?,?,?,?,,?,,?,?,?,?,?)}]; SQL状态[null]; 错误代码[0]; 没有为参数编号11设置该值.嵌套异常是com.microsoft.sqlserver.jdbc.SQLServerException:未在org.springframework.jdbc的org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)中为参数编号11设置该值. support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)在org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)在org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1095)在org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1131)

该应用程序部署在WAS 8.5.5上并使用jdbc驱动程序版本4.2.重新启动服务器时,此问题不再发生.生成的以下调用语句看起来不正确.连续逗号没有?它们之间.

{call test.usp_xxx_GetCompanyDetails(?,?,?,?,?,,?,,?,?,?,?,?)}

存储过程有10个参数.以下是存储过程的定义:

CREATE PROCEDURE [test].[usp_xxx_GetCompanyDetails]
(
    @ANumber        int,
    @CompanyId      int,
    @UserRole       varchar(15),
    @RequestId      varchar(100),
    @CompanyCode    varchar(5),
    @BaseSystem     varchar(5),
    @PType          varchar(20),    
    @PId            varchar(40),
    @IsActive       bit,     
    @responseData   xml OUT
)
Run Code Online (Sandbox Code Playgroud)

以下是调用存储过程的java代码.它使用spring数据进行调用.

 private String executeProc(Integer aNumber,Integer companyId, String baseSystem, 
                String role,String companyCode,String requestId, String pType,String pId,
                boolean isActive ) throws SQLException {

            SQLXML responseData=null;
            Map<String,Object> inputParams= new HashMap<>();
            inputParams.put("ANumber", aNumber);
            inputParams.put("CompanyId", companyId);
            inputParams.put("UserRole", role);
            inputParams.put("RequestId", requestId);
            inputParams.put("CompanyCode", companyCode);
            inputParams.put("BaseSystem", baseSystem);
            inputParams.put("PType", pType);
            inputParams.put("PId", pId);
            inputParams.put("IsActive", isActive);
            inputParams.put("ResponseData", responseData);

            Map<String, Object> result = this.execute(inputParams);
            String responseXMLString = ((SQLXML) result.get("ResponseData")).getString();

            return responseXMLString;
        }
Run Code Online (Sandbox Code Playgroud)

什么可能出错.

use*_*900 7

你有11个绑定参数(?)和空参数, ,.将其移除以使用具有9个输入参数和1个输出参数的过程

{call test.usp_xxx_GetCompanyDetails(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
Run Code Online (Sandbox Code Playgroud)

  • 我差点投票,但程序有10个参数.`OUT`参数仍然是一个参数. (3认同)