简体   繁体   中英

nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The index 0 of the output parameter is not valid

I am trying to executed a procedure in MSSQL from spring batch item reader. I am getting the exception below. I am able to executed the same procedure from any sql client. The procedure has 2 output parameters. Any help is deeply appreciated.

This is the code,

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");
                        }
                    });

exception below,

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)

Use "set nocount on" in your stored procedure before begin statement. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM