admin 管理员组

文章数量: 1086019

we have a simple java code with a call to a user-defined procedure on SQLSERVER database. We were using sqljdbc42-6.0.8112 driver and everything was fine. here's the call

   String sql="{ CALL DBO.MY_PROCEDURE('ValueOne',valueTwo,'ValueThree',?)}";
   CallableStatement cstmt = connection.prepareCall(sql);
   cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
   cstmt.execute();

Please note the use of litteral values and the last one is the optput of Integer type.

And Here's the definition of the procedure

CREATE PROCEDURE [dbo].[MY_PROCEDURE](@valueOne NVARCHAR(30),@valueTwo NUMERIC,@valueThree NVARCHAR(500),@returnValue SMALLINT OUTPUT)

But, recently, we upgraded our system and we upgraded JDBC driver to mssql-jdbc-12.6.2.jre11 and this call started throwing errors

The formal parameter "@valueOne" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output.

I re-wrote the code to use the bind values instead of litteral values.

String sql = "{ CALL MY_PROCEDURE (?,?,?,?) }";
CallableStatement cstmt = connection.prepareCall(sql);
cstmt.setString(1, valueOne);
cstmt.setLong(2, valueTwo);
cstmt.setString(3, valueThree);
cstmt.registerOutParameter(4, java.sql.Types.INTEGER);

and this is perfectly working.

I just don't understand why this gives an error when used with litteral values but works with bind values.

Anybody has any idea please?

Thanks in advance!

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)