2013-06-24 50 views
7

我有一个SQL Server 2008程序正在返回一个输出参数,我正在从java调用它。下面com.microsoft.sqlserver.jdbc.SQLServerException:'@ P0'附近的语法不正确

存储过程的代码我的代码被赋予是

Create PROCEDURE countInfected @infected int out 
AS 
Select @infected = COUNT(*) from userInfo 
where userID NOT IN (Select userID from deletedInfo); 

Java的长途区号

CallableStatement infected = null; 
infected = con.prepareCall("call countInfected(?)"); 
infected.registerOutParameter(1, java.sql.Types.INTEGER); 
infected.execute(); 
System.out.println("Infected"+ infected.getInt(1)); 

但infected.execute();正在生成以下错误

com.microsoft.sqlserver.jdbc.SQLServerException:附近有语法错误@ P0'

亲切指导我在哪里的问题

+0

哪行触发错误? – GregHNZ

+0

infected.execute(); – WiXXeY

+0

这对你有什么好处:https://groups.google.com/forum/#!msg/mybatis-user/DxLHOn8LZU0/dFRgaIL7Ez8J?基本上把括号括起来,就像这个“{call countInfected(?)}”(我的SQL Server被烤了,所以我不能检查)。 – GregHNZ

回答

10

正如this link提供了建议通过@GregHNZ,SQL Server需要围绕该调用的一组花括号。

在你的代码行是这样的:

infected = con.prepareCall("{ call countInfected(?) }");