What can cause the SQL Server JDBC error 'The value is not set for the parameter number 0' for an output parameter access?

主宰稳场 提交于 2019-12-04 03:28:22

on your parameters, are you just declaring them or are you setting them to a default value? try setting them to a default value of null or something and see if you still get the error.

sql server doesn't like it if you have a parameter not set to a default value and you don't pass a value to it when you exec the stored procedure.

Are you registering the output parameters? According the the docs "All OUT parameters must be registered before a stored procedure is executed."

There are a couple things that come to mind:

  1. You haven't got a RETURN x (where x is an INT representing the outcome of processing, 0 = success, anything else represent a warning or an error).
  2. Your client code doesn't assign a parameter for the return value in addition to your output parameter.

Hope this helps,

Bill

Decompiling the com.microsoft.sqlserver.jdbc.SQLServerCallableStatement class suggests that 'parameter number 0' is the stored procedure return value.

Thats correct. If your stored procedure definition has 11 input/output parameters, you actually need to define 12 in your calling code. Parameter 0 is the return code.

For example with a SP with one input and one output parameter, in SSMS you run this:

DECLARE @ReturnValue INT
DECLARE @P1 INT, @P2 INT

EXEC @ReturnValue= YourSP(@P1,@P2 OUTPUT)

You actually have three parameters to deal with here, not two.

ChrisR

In case anyone still getting this problem on SQL server 2008.

I had the same problem on an update statement with trying to set a Timestamp for a DateTime field. The offending field was in a where clause at a different index from the reported one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!