我正在尝试从Spring批量项目阅读器中执行MSSQL中的过程。我在下面得到例外。我能够从任何sql客户端执行相同的过程。该过程有2个输出参数。非常感谢任何帮助。
这是代码,
StoredProcedureItemReader<ReturnData> reader = new StoredProcedureItemReader<ReturnData>();
try {
reader.setDataSource(batchOMSDataSource);
reader.setProcedureName("dbo.ItemReturnEligibilty_r");
reader.setParameters(
new SqlParameter[] {
//new SqlParameter("WarehouseNumber", java.sql.Types.INTEGER),
new SqlParameter("ItemNumber", java.sql.Types.VARCHAR),
new SqlParameter("IsEligibleForReturn", java.sql.Types.VARCHAR),
});
reader.setPreparedStatementSetter(
new PreparedStatementSetter() {
public void setValues(PreparedStatement ps)
throws SQLException {
//ps.setInt(0, 847);
ps.setString(1, "ItemNumber");
ps.setString(2, "IsEligibleForReturn");
}
});
以下例外,
Caused by: org.springframework.dao.TransientDataAccessResourceException: Executing stored procedure; SQL [{call dbo.ItemReturnEligibilty_r(?, ?)}]; The index 0 of the output parameter is not valid.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The index 0 of the output parameter is not valid.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:226)
at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:406)
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:144)
答案 0 :(得分:0)
在开始声明之前,在存储过程中使用“ set nocount on”。 谢谢