我从从 Java 代码调用存储过程的代码中收到以下错误:
Exception Trace {} org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call test.usp_xxx_GetCompanyDetails(?, ?, ?, ?, ?, , ?, , ?, ?, ?, ?, ?)}]; SQL state [null]; error code [0]; The value is not set for the parameter number 11.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 11. at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1095) at 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
)
以下是调用存储过程的 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;
}
可能出了什么问题。
最佳答案
您有 11 个绑定(bind)参数 (?) 和空参数 , ,
。删除它以使用具有 9 个输入参数和 1 个输出参数的过程
{call test.usp_xxx_GetCompanyDetails(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
关于java - JDBC SQL 服务器 : The value is not set for the parameter number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52143396/