简体   繁体   中英

java.sql.SQLException: Parameter #9 has not been set

hello I'm trying to execute mssql stored procedure from hibernate. Procedure has 8 input parameters and no output. But I get java.sql.SQLException: Parameter #9 has not been set whuli executing.

<sql-query name="insertMyData" callable="true">
        { ? = call InsertMyData(?,?,?,?,?,?,?,?) }
</sql-query>

Java invocation

Query query = m_entityManager.createNamedQuery("insertMyData");
        query.setParameter(1, transaction.getGuid());
        query.setParameter(2, new Date());

........ other parameters specified

Stored procedure

CREATE PROC dbo.insertMyData 
    @ID uniqueidentifier, 
    ...... 7 more parameters
AS 
BEGIN
    INSERT INTO dbo.TestData VALUES (
        @ID,
           ........ 7 more parameters

    )
END

My bad with my earlier suggestion:

According to https://forum.hibernate.org/viewtopic.php?f=1&t=986612

Another person with the same issue, got it resolved by removing the "? =" since there was not 'return' defined for the quesry. I would suggest you try the same.

Hope this helps.

Seems like you have ignored the first ? and called setParameter only 8 times for the ? inside the procedure call.

This is how you should set your first parameter:

statement.registerOutParameter(1, Types.VARCHAR); //Assuming statement is your CallableStatement and return type of procedure is Varchar

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